package com.sls.game.service.impl;

import java.io.File;
import java.io.UnsupportedEncodingException;
import java.net.InetAddress;
import java.net.URLEncoder;
import java.net.UnknownHostException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import javax.annotation.Resource;
import javax.xml.parsers.ParserConfigurationException;

import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import com.google.gson.Gson;
import com.sls.core.common.CommonUtil;
import com.sls.core.http.HttpClient;
import com.sls.core.socket.Head;
import com.sls.core.socket.OrderIdServer;
import com.sls.core.socket.ServerDisponseException;
import com.sls.core.socket.StartMain;
import com.sls.core.util.DataConversion;
import com.sls.core.util.ProcessString;
import com.sls.core.util.PropertiesUtil;
import com.sls.core.util.ServerDateAndTime;
import com.sls.core.util.SlsDataCheck;
import com.sls.core.util.UtilMD5Encryption;
import com.sls.game.assist.Helper;
import com.sls.game.base.module.BaseDeal;
import com.sls.game.common.DeductionRefund;
import com.sls.game.constant.ExceptionCodeDes;
import com.sls.game.dao.DownstreamUserDAO;
import com.sls.game.dao.EBaiMiDAO;
import com.sls.game.dao.EnLinkProductDAO;
import com.sls.game.dao.EnlinkProductAreaServerDAO;
import com.sls.game.dao.GoodsInfoManageDAO;
import com.sls.game.dao.GoodsOrderDAO;
import com.sls.game.dao.GoodsOrderLogDAO;
import com.sls.game.dao.GoodsSupplyManageDAO;
import com.sls.game.dao.NutsNetGoodsInfoDAO;
import com.sls.game.dao.OhFeiGoodsAreaServerDAO;
import com.sls.game.dao.OhFeiGoodsInfoDAO;
import com.sls.game.dao.ProductBrandDAO;
import com.sls.game.dao.SevenNineNineSixDAO;
import com.sls.game.dao.SpecialPriceSystemDAO;
import com.sls.game.dao.SupplyRuleDAO;
import com.sls.game.dao.TencentGoodsInfoDAO;
import com.sls.game.dao.enfu.EnfuAccountTypeDAO;
import com.sls.game.dao.enfu.EnfuAreaDAO;
import com.sls.game.dao.enfu.EnfuChargeTypeDAO;
import com.sls.game.dao.enfu.EnfuChoosegemDAO;
import com.sls.game.dao.enfu.EnfuGoodsDAO;
import com.sls.game.dao.enfu.EnfuGoodsDetailDAO;
import com.sls.game.dao.enfu.EnfuServerDAO;
import com.sls.game.dao.jpay.JpayAreaDAO;
import com.sls.game.dao.jpay.JpayGoodsDAO;
import com.sls.game.dao.nutsnet.AccountTypeDAO;
import com.sls.game.dao.nutsnet.ChargeTypeInfoDAO;
import com.sls.game.dao.nutsnet.ChooseGemDAO;
import com.sls.game.dao.nutsnet.NutsNetGoodsAreaDAO;
import com.sls.game.dao.nutsnet.NutsNetGoodsDetailTopDAO;
import com.sls.game.dao.nutsnet.NutsNetGoodsServerDAO;
import com.sls.game.dao.wogreat.WogreatAccountDAO;
import com.sls.game.dao.wogreat.WogreatAsDAO;
import com.sls.game.dao.wogreat.WogreatDAO;
import com.sls.game.dao.wogreat.WogreatRechargeDAO;
import com.sls.game.dao.xingxitian.XingAccountTypeDAO;
import com.sls.game.dao.xingxitian.XingChargeTypeDAO;
import com.sls.game.dao.xingxitian.XingDisCountDAO;
import com.sls.game.dao.xingxitian.XingGameAreaSrvDAO;
import com.sls.game.dao.xingxitian.XingGoodsTopDAO;
import com.sls.game.dao.xingxitian.XingParvalueDAO;
import com.sls.game.page.Pagination;
import com.sls.game.parser.deductrefund.DeductionRefundResParse;
import com.sls.game.parser.nutsnet.NutsNetAssembleHttpUrl;
import com.sls.game.parser.nutsnet.NutsNetResponseDomParseXml;
import com.sls.game.parser.nutsnet.NutsNetServerSaxParseXml;
import com.sls.game.parser.nutsnet.TradeResponseSaxParseXml;
import com.sls.game.parser.ohfei.OhFeiAssembleHttpUrl;
import com.sls.game.parser.ohfei.OhFeiResOfDomParseXml;
import com.sls.game.parser.ohfei.OhFeiServerSaxParseXml;
import com.sls.game.pojo.DeductionRefundInfo;
import com.sls.game.pojo.DownstreamUserInfo;
import com.sls.game.pojo.GoodsManageInfo;
import com.sls.game.pojo.GoodsOrderInfo;
import com.sls.game.pojo.GoodsOrderLog;
import com.sls.game.pojo.GoodsSupplyManageInfo;
import com.sls.game.pojo.NutsNetGoodsInfo;
import com.sls.game.pojo.NutsNetServerInfo;
import com.sls.game.pojo.NutsNetTradeResInfo;
import com.sls.game.pojo.OhFeiGoodsAreaServerInfo;
import com.sls.game.pojo.OhFeiGoodsInfo;
import com.sls.game.pojo.OhFeiServerInfo;
import com.sls.game.pojo.OhFeiTradeInfo;
import com.sls.game.pojo.ProductBrandInfo;
import com.sls.game.pojo.SLSHttpInterfaceInfo;
import com.sls.game.pojo.SpecialPriceSystemInfo;
import com.sls.game.pojo.TencentGoodsInfo;
import com.sls.game.pojo.enlink.EnLinkProduct;
import com.sls.game.pojo.enlink.EnLinkRequestTradeInfo;
import com.sls.game.pojo.enlink.EnLinkTradeInfo;
import com.sls.game.pojo.enlink.EnlinkProductAreaServer;
import com.sls.game.pojo.jieyitong.JieyitongAreaServerInfo;
import com.sls.game.pojo.jieyitong.JieyitongGoodsInfo;
import com.sls.game.pojo.nutsnet.AccountTypeInfo;
import com.sls.game.pojo.nutsnet.ChargeTypeInfo;
import com.sls.game.pojo.nutsnet.ChooseGemInfo;
import com.sls.game.pojo.nutsnet.NutsNetGoodsAreaInfo;
import com.sls.game.pojo.nutsnet.NutsNetGoodsDetailTop;
import com.sls.game.pojo.nutsnet.NutsNetGoodsServerInfo;
import com.sls.game.pojo.wogreat.WogreatAreaServer;
import com.sls.game.pojo.wogreat.WogreatProduct;
import com.sls.game.querybean.SpecialPriceSystemQuery;
import com.sls.game.service.EKHInterfaceService;
import com.sls.game.service.SLSHttpInterfaceService;
import com.sls.game.service.TencentService;
import com.sls.game.supply.deal.EBaiMiTradeDeal;
import com.sls.game.supply.deal.EnfuTradeDeal;
import com.sls.game.supply.deal.JpayTradeDeal;
import com.sls.game.supply.deal.SevenNineNineSixTradeDeal;
import com.sls.game.supply.deal.WogreatTradeDeal;
import com.sls.game.supply.deal.XinHeTradeDeal;
import com.sls.game.supply.deal.XingQiTianTradeOfDeal;
import com.sls.game.supply.deal.YunEnTradeDeal;

/**
 * 
 * @description 手拉手开放给下游用户的Http服务
 * @author Wangxuegang
 * @date 2012-10-12
 * 
 */
@Service("sLSHttpInterfaceService")
public class SLSHttpInterfaceServiceImpl implements SLSHttpInterfaceService {

	private static Logger log = Logger
			.getLogger(SLSHttpInterfaceServiceImpl.class);

	private Gson gson = null;

	public SLSHttpInterfaceServiceImpl() {
		gson = CommonUtil.gson();
	}

	@Resource(name = "eKHInterfaceserviceImp")
	private EKHInterfaceService ekhinterface;

	@Value("${order.ip}")
	private String orderIp;
	@Value("${order.port}")
	private String orderPort;
	/**
	 * 品牌DAO
	 */
	private ProductBrandDAO productBrandDAO;

	/**
	 * 商品信息DAO
	 */
	private GoodsInfoManageDAO goodsInfoManageDAO;

	/**
	 * 特殊价格体系DAO
	 */
	private SpecialPriceSystemDAO specialPriceSystemDAO;

	/**
	 * 网游充值订单表DAO
	 */
	private GoodsOrderDAO goodsOrderDAO;

	/**
	 * 商品供应表DAO
	 */
	private GoodsSupplyManageDAO goodsSupplyManageDAO;

	/**
	 * 游戏供货规则表DAO
	 */
	private SupplyRuleDAO supplyRuleDAO;

	/**
	 * 坚果网络商品信息DAO
	 */
	private NutsNetGoodsInfoDAO nutsNetGoodsInfoDAO;

	/**
	 * 殴飞区服DAO
	 */
	private OhFeiGoodsAreaServerDAO ohFeiGoodsAreaServerDAO;

	/**
	 * 殴飞产品DAO
	 */
	private OhFeiGoodsInfoDAO ohFeiGoodsInfoDAO;

	/**
	 * 下游用户DAO
	 */
	private DownstreamUserDAO downstreamUserDAO;

	/**
	 * 腾讯原始商品DAO
	 */
	private TencentGoodsInfoDAO tencentGoodsInfoDAO;

	private ChargeTypeInfoDAO chargeTypeInfoDAO;

	private GoodsOrderLogDAO goodsOrderLogDAO;

	private NutsNetGoodsAreaDAO nutsNetGoodsAreaDAO;

	private NutsNetGoodsServerDAO nutsNetGoodsServerDAO;

	private AccountTypeDAO accountTypeDAO;

	private ChooseGemDAO chooseGemDAO;

	@Resource(name = "enfuGoodsDAO")
	private EnfuGoodsDAO enfuGoodsDAO;

	@Resource(name = "enfuAccountTypeDAO")
	private EnfuAccountTypeDAO enfuAccountTypeDAO;

	@Resource(name = "enfuChargeTypeDAO")
	private EnfuChargeTypeDAO enfuChargeTypeDAO;

	@Resource(name = "enfuAreaDAO")
	private EnfuAreaDAO enfuAreaDAO;

	@Resource(name = "enfuChoosegemDAO")
	private EnfuChoosegemDAO enfuChoosegemDAO;

	@Resource(name = "enfuServerDAO")
	private EnfuServerDAO enfuServerDAO;

	@Resource(name = "enfuGoodsDetailDAO")
	private EnfuGoodsDetailDAO enfuGoodsDetailDAO;

	private NutsNetGoodsDetailTopDAO nutsNetGoodsDetailTopDAO;
	@Resource(name = "enLinkProductDAO")
	private EnLinkProductDAO enLinkProductDAO;
	@Resource(name = "enLinkProductAreaServerDAO")
	private EnlinkProductAreaServerDAO enLinkAreaServerDAO;
	@Resource(name = "jpayGoodsDAO")
	private JpayGoodsDAO jpayGoodsDAO;
	@Resource(name = "jpayAreaDAO")
	private JpayAreaDAO jpayAreaDAO;
	@Resource(name = "eBaiMiDAO")
	private EBaiMiDAO eBaiMiDAO;
	@Resource(name = "sevenNineNineSixDAO")
	private SevenNineNineSixDAO snnsDAO;
	@Resource(name = "wogreatAccountDAO")
	private WogreatAccountDAO wogreatAccountDAO;
	@Resource(name = "wogreatRechargeDAO")
	private WogreatRechargeDAO wogreatRechargeDAO;
	@Resource(name = "wogreatAsDAO")
	private WogreatAsDAO wogreatAsDAO;
	@Resource(name = "wogreatDAO")
	private WogreatDAO wogreatDAO;
	@Resource(name = "xinHeTradeDeal")
	private XinHeTradeDeal xinHeTradeDeal;

	private XingDisCountDAO xingDisCountDAO;

	private XingGoodsTopDAO xingGoodsTopDAO;

	private XingParvalueDAO xingParvalueDAO;

	private XingChargeTypeDAO xingChargeTypeDAO;

	private XingAccountTypeDAO xingAccountTypeDAO;

	private XingGameAreaSrvDAO xingGameAreaSrvDAO;
	@Resource(name = "tencentService")
	private TencentService tencentService;

	public XingGameAreaSrvDAO getXingGameAreaSrvDAO() {
		return xingGameAreaSrvDAO;
	}

	@Resource(name = "xingGameAreaSrvDAO")
	public void setXingGameAreaSrvDAO(XingGameAreaSrvDAO xingGameAreaSrvDAO) {
		this.xingGameAreaSrvDAO = xingGameAreaSrvDAO;
	}

	public XingAccountTypeDAO getXingAccountTypeDAO() {
		return xingAccountTypeDAO;
	}

	@Resource(name = "xingAccountTypeDAO")
	public void setXingAccountTypeDAO(XingAccountTypeDAO xingAccountTypeDAO) {
		this.xingAccountTypeDAO = xingAccountTypeDAO;
	}

	public XingChargeTypeDAO getXingChargeTypeDAO() {
		return xingChargeTypeDAO;
	}

	@Resource(name = "xingChargeTypeDAO")
	public void setXingChargeTypeDAO(XingChargeTypeDAO xingChargeTypeDAO) {
		this.xingChargeTypeDAO = xingChargeTypeDAO;
	}

	public XingParvalueDAO getXingParvalueDAO() {
		return xingParvalueDAO;
	}

	@Resource(name = "xingParvalueDAO")
	public void setXingParvalueDAO(XingParvalueDAO xingParvalueDAO) {
		this.xingParvalueDAO = xingParvalueDAO;
	}

	public XingGoodsTopDAO getXingGoodsTopDAO() {
		return xingGoodsTopDAO;
	}

	@Resource(name = "xingGoodsTopDAO")
	public void setXingGoodsTopDAO(XingGoodsTopDAO xingGoodsTopDAO) {
		this.xingGoodsTopDAO = xingGoodsTopDAO;
	}

	public XingDisCountDAO getXingDisCountDAO() {
		return xingDisCountDAO;
	}

	@Resource(name = "xingDisCountDAO")
	public void setXingDisCountDAO(XingDisCountDAO xingDisCountDAO) {
		this.xingDisCountDAO = xingDisCountDAO;
	}

	public NutsNetGoodsDetailTopDAO getNutsNetGoodsDetailTopDAO() {
		return nutsNetGoodsDetailTopDAO;
	}

	@Resource(name = "nutsNetGoodsDetailTopDAO")
	public void setNutsNetGoodsDetailTopDAO(
			NutsNetGoodsDetailTopDAO nutsNetGoodsDetailTopDAO) {
		this.nutsNetGoodsDetailTopDAO = nutsNetGoodsDetailTopDAO;
	}

	public ChooseGemDAO getChooseGemDAO() {
		return chooseGemDAO;
	}

	@Resource(name = "chooseGemDAO")
	public void setChooseGemDAO(ChooseGemDAO chooseGemDAO) {
		this.chooseGemDAO = chooseGemDAO;
	}

	public AccountTypeDAO getAccountTypeDAO() {
		return accountTypeDAO;
	}

	@Resource(name = "accountTypeDAO")
	public void setAccountTypeDAO(AccountTypeDAO accountTypeDAO) {
		this.accountTypeDAO = accountTypeDAO;
	}

	public NutsNetGoodsServerDAO getNutsNetGoodsServerDAO() {
		return nutsNetGoodsServerDAO;
	}

	@Resource(name = "nutsNetGoodsServerDAO")
	public void setNutsNetGoodsServerDAO(
			NutsNetGoodsServerDAO nutsNetGoodsServerDAO) {
		this.nutsNetGoodsServerDAO = nutsNetGoodsServerDAO;
	}

	public NutsNetGoodsAreaDAO getNutsNetGoodsAreaDAO() {
		return nutsNetGoodsAreaDAO;
	}

	@Resource(name = "nutsNetGoodsAreaDAO")
	public void setNutsNetGoodsAreaDAO(NutsNetGoodsAreaDAO nutsNetGoodsAreaDAO) {
		this.nutsNetGoodsAreaDAO = nutsNetGoodsAreaDAO;
	}

	public GoodsOrderLogDAO getGoodsOrderLogDAO() {
		return goodsOrderLogDAO;
	}

	@Resource(name = "goodsOrderLogDAO")
	public void setGoodsOrderLogDAO(GoodsOrderLogDAO goodsOrderLogDAO) {
		this.goodsOrderLogDAO = goodsOrderLogDAO;
	}

	public ChargeTypeInfoDAO getChargeTypeInfoDAO() {
		return chargeTypeInfoDAO;
	}

	@Resource(name = "chargeTypeInfoDAO")
	public void setChargeTypeInfoDAO(ChargeTypeInfoDAO chargeTypeInfoDAO) {
		this.chargeTypeInfoDAO = chargeTypeInfoDAO;
	}

	public TencentGoodsInfoDAO getTencentGoodsInfoDAO() {
		return tencentGoodsInfoDAO;
	}

	@Resource(name = "tencentGoodsInfoDAO")
	public void setTencentGoodsInfoDAO(TencentGoodsInfoDAO tencentGoodsInfoDAO) {
		this.tencentGoodsInfoDAO = tencentGoodsInfoDAO;
	}

	public DownstreamUserDAO getDownstreamUserDAO() {
		return downstreamUserDAO;
	}

	@Resource(name = "downstreamUserDAO")
	public void setDownstreamUserDAO(DownstreamUserDAO downstreamUserDAO) {
		this.downstreamUserDAO = downstreamUserDAO;
	}

	public OhFeiGoodsInfoDAO getOhFeiGoodsInfoDAO() {
		return ohFeiGoodsInfoDAO;
	}

	@Resource(name = "ohFeiGoodsInfoDAO")
	public void setOhFeiGoodsInfoDAO(OhFeiGoodsInfoDAO ohFeiGoodsInfoDAO) {
		this.ohFeiGoodsInfoDAO = ohFeiGoodsInfoDAO;
	}

	public OhFeiGoodsAreaServerDAO getOhFeiGoodsAreaServerDAO() {
		return ohFeiGoodsAreaServerDAO;
	}

	@Resource(name = "ohFeiGoodsAreaServerDAO")
	public void setOhFeiGoodsAreaServerDAO(
			OhFeiGoodsAreaServerDAO ohFeiGoodsAreaServerDAO) {
		this.ohFeiGoodsAreaServerDAO = ohFeiGoodsAreaServerDAO;
	}

	public NutsNetGoodsInfoDAO getNutsNetGoodsInfoDAO() {
		return nutsNetGoodsInfoDAO;
	}

	@Resource(name = "nutsNetGoodsInfoDAO")
	public void setNutsNetGoodsInfoDAO(NutsNetGoodsInfoDAO nutsNetGoodsInfoDAO) {
		this.nutsNetGoodsInfoDAO = nutsNetGoodsInfoDAO;
	}

	public SupplyRuleDAO getSupplyRuleDAO() {
		return supplyRuleDAO;
	}

	@Resource(name = "supplyRuleDAO")
	public void setSupplyRuleDAO(SupplyRuleDAO supplyRuleDAO) {
		this.supplyRuleDAO = supplyRuleDAO;
	}

	public GoodsSupplyManageDAO getGoodsSupplyManageDAO() {
		return goodsSupplyManageDAO;
	}

	@Resource(name = "goodsSupplyManageDAO")
	public void setGoodsSupplyManageDAO(
			GoodsSupplyManageDAO goodsSupplyManageDAO) {
		this.goodsSupplyManageDAO = goodsSupplyManageDAO;
	}

	public SpecialPriceSystemDAO getSpecialPriceSystemDAO() {
		return specialPriceSystemDAO;
	}

	@Resource(name = "specialPriceSystemDAO")
	public void setSpecialPriceSystemDAO(
			SpecialPriceSystemDAO specialPriceSystemDAO) {
		this.specialPriceSystemDAO = specialPriceSystemDAO;
	}

	public ProductBrandDAO getProductBrandDAO() {
		return productBrandDAO;
	}

	@Resource(name = "productBrandDAO")
	public void setProductBrandDAO(ProductBrandDAO productBrandDAO) {
		this.productBrandDAO = productBrandDAO;
	}

	public GoodsInfoManageDAO getGoodsInfoManageDAO() {
		return goodsInfoManageDAO;
	}

	@Resource(name = "goodsInfoManageDAO")
	public void setGoodsInfoManageDAO(GoodsInfoManageDAO goodsInfoManageDAO) {
		this.goodsInfoManageDAO = goodsInfoManageDAO;
	}

	public GoodsOrderDAO getGoodsOrderDAO() {
		return goodsOrderDAO;
	}

	@Resource(name = "goodsOrderDAO")
	public void setGoodsOrderDAO(GoodsOrderDAO goodsOrderDAO) {
		this.goodsOrderDAO = goodsOrderDAO;
	}

	/**
	 * 商品品牌同步
	 * 
	 * @param body
	 * @param head
	 * @return
	 * @throws ServerDisponseException
	 * @throws ParserConfigurationException
	 */
	@Override
	public String queryAllBrand(String body, Head head)
			throws ServerDisponseException {
		if (log.isInfoEnabled()) {
			log.info("进入Service开始处理[" + head.getRequestId() + "]的请求");
		}

		ProductBrandInfo info = gson.fromJson(body, ProductBrandInfo.class);
		// 返回给上层对象
		SLSHttpInterfaceInfo sLSHttpInterfaceInfo = new SLSHttpInterfaceInfo();

		// ***** 下游用户身份校验 *****
		String userNo = info.getUserNo();
		String userIP = info.getClientIp();
		String result = checkIdentity(userNo, userIP, false);
		if ("104".equals(result)) { // 合作方用户不存在
			sLSHttpInterfaceInfo.setResMsg("FAILED");
			sLSHttpInterfaceInfo.setFailedCode("104");
			sLSHttpInterfaceInfo.setFailedReason("合作方用户不存在");
			String resultBody = null;
			resultBody = gson.toJson(sLSHttpInterfaceInfo);
			return resultBody;
		} else { // 身份校验通过
			try {
				Pagination<ProductBrandInfo> paginationList = productBrandDAO
						.queryPaginationList(info);
				if (paginationList != null) {
					return gson.toJson(paginationList);
				}
			} catch (Exception e) {
				log.error("Service处理[" + head.getRequestId() + "]的请求出现异常！", e);
				throw new ServerDisponseException(
						ExceptionCodeDes.ACCESS_DATABASE_ERROR.getCode(),
						ExceptionCodeDes.ACCESS_DATABASE_ERROR.getDescription());
			}

			return null;
		}
	}

	/**
	 * 查询某一品牌下的所有商品
	 * 
	 * @param body
	 * @param head
	 * @return
	 * @throws ServerDisponseException
	 */
	@Override
	public String queryGoodsOfByBrandId(String body, Head head)
			throws ServerDisponseException {
		if (log.isInfoEnabled()) {
			log.info("进入Service开始处理[" + head.getRequestId() + "]的请求");
		}

		GoodsManageInfo goodsInfo = gson.fromJson(body, GoodsManageInfo.class);
		boolean flag = checkDataOfQueryGoodsOfByBrandId(goodsInfo,
				head.getRequestId());
		if (flag) { // 数据校验通过
			// 返回给上层对象
			SLSHttpInterfaceInfo sLSHttpInterfaceInfo = new SLSHttpInterfaceInfo();

			// ***** 下游用户身份校验 *****
			String userNo = goodsInfo.getUserNo();
			String userIP = goodsInfo.getClientIp();
			String result = checkIdentity(userNo, userIP, false);
			if ("104".equals(result)) {
				sLSHttpInterfaceInfo.setResMsg("FAILED");
				sLSHttpInterfaceInfo.setFailedCode("104");
				sLSHttpInterfaceInfo.setFailedReason("合作方用户不存在");
				String resultBody = null;
				resultBody = gson.toJson(sLSHttpInterfaceInfo);
				return resultBody;
			} else { // 身份校验通过
				Pagination<?> page = null;
				// 品牌Id
				String brandId = goodsInfo.getGoodsCategoryId();
				try {
					DownstreamUserInfo userInfo = this.downstreamUserDAO
							.queryUserByUserNO(userNo);
					if (userInfo != null) {
						String templateCode = userInfo.getTemplateCode();
						if (StringUtils.isNotEmpty(templateCode)) {
							SpecialPriceSystemQuery priceSystemInfo = new SpecialPriceSystemQuery();
							priceSystemInfo.setBrandId(brandId);
							priceSystemInfo.setTemplateCode(templateCode);
							priceSystemInfo
									.setPageSize(goodsInfo.getPageSize());
							priceSystemInfo.setCurrentPage(goodsInfo
									.getCurrentPage());
							page = this.specialPriceSystemDAO
									.querySpecialPriceSystem(priceSystemInfo);
						}
					} else {
						GoodsManageInfo goodsManageInfo = new GoodsManageInfo();
						goodsManageInfo.setGoodsCategoryId(brandId);
						goodsManageInfo.setGoodsState("1"); // 上架的商品
						goodsManageInfo.setUserNo(userNo);
						goodsManageInfo.setPageSize(goodsInfo.getPageSize());
						goodsManageInfo.setCurrentPage(goodsInfo
								.getCurrentPage());
						page = this.goodsInfoManageDAO
								.queryPaginationList(goodsManageInfo);
					}

					return gson.toJson(page);
				} catch (Exception e) {
					log.error("Service处理[" + head.getRequestId() + "]的请求出现异常！",
							e);
					throw new ServerDisponseException(
							ExceptionCodeDes.ACCESS_DATABASE_ERROR.getCode(),
							ExceptionCodeDes.ACCESS_DATABASE_ERROR
									.getDescription());
				}
			}
		}

		return null;
	}

	/**
	 * 某一商品的详细信息查询
	 * 
	 * @param body
	 * @param head
	 * @return
	 * @throws ServerDisponseException
	 */
	@Override
	public String saveQueryOneGoodsOfDetail(String body, Head head)
			throws ServerDisponseException {
		if (log.isInfoEnabled()) {
			log.info("进入Service开始处理[" + head.getRequestId() + "]的请求");
		}

		SLSHttpInterfaceInfo info = gson.fromJson(body,
				SLSHttpInterfaceInfo.class);
		boolean flag = checkDataOfQueryOneGoodsOfDetail(info,
				head.getRequestId());
		if (flag) { // 校验通过
			// ***** 下游用户身份校验 *****
			String userNo = info.getUserNo();
			String userIP = info.getClientIp();
			String result = checkIdentity(userNo, userIP, false);
			if ("104".equals(result)) {
				// 返回给上层对象
				SLSHttpInterfaceInfo sLSHttpInterfaceInfo = new SLSHttpInterfaceInfo();
				sLSHttpInterfaceInfo.setResMsg("FAILED");
				sLSHttpInterfaceInfo.setFailedCode("104");
				sLSHttpInterfaceInfo.setFailedReason("合作方用户不存在");
				String resultBody = null;
				resultBody = gson.toJson(sLSHttpInterfaceInfo);
				return resultBody;
			} else { // 身份校验通过
				// 商品Id
				String goodsId = info.getGoodsId();
				List<GoodsSupplyManageInfo> supplyList = null;
				GoodsSupplyManageInfo goodsSupplyManageInfo = null;

				GoodsSupplyManageInfo goodsSupplyManageInfo1 = new GoodsSupplyManageInfo();
				goodsSupplyManageInfo1.setGoodsId(goodsId);
				goodsSupplyManageInfo1.setGoodsState("1"); // 上架

				// 查询价格最低的供货商
				supplyList = goodsSupplyManageDAO
						.queryMininunPrice(goodsSupplyManageInfo1);
				if (supplyList != null && supplyList.size() > 0) {
					goodsSupplyManageInfo = supplyList.get(0);
				}
				// 供应商Id
				String suppliersId = "";
				// 原始商品Id
				String originalGoodsId = "";
				String goodsName = "";
				String brandId = "";
				String brandName = "";
				String rechargeMode = "";
				if (goodsSupplyManageInfo != null) {
					suppliersId = goodsSupplyManageInfo.getSuppliersId();
					originalGoodsId = goodsSupplyManageInfo
							.getOriginalGoodsId();
					goodsName = goodsSupplyManageInfo.getGoodsName();
					brandId = goodsSupplyManageInfo.getGoodsCategoryId();
					brandName = goodsSupplyManageInfo.getBrandName();
					rechargeMode = goodsSupplyManageInfo.getRechargeMode();
				}

				String areaServer = "";
				String rechargeLimit = "";

				SLSHttpInterfaceInfo sLSHttpInterfaceInfo = new SLSHttpInterfaceInfo();
				sLSHttpInterfaceInfo.setGoodsId(goodsId);
				sLSHttpInterfaceInfo.setGoodsName(goodsName);
				sLSHttpInterfaceInfo.setGoodsCategoryId(brandId);
				sLSHttpInterfaceInfo.setBrandName(brandName);
				sLSHttpInterfaceInfo.setRechargeMode(rechargeMode);

				/**
				 * 根据供应商Id，判断选择那个供应商的商品的详细信息
				 */
				if ("20121000".equals(suppliersId)) { // 殴飞
					sLSHttpInterfaceInfo = getGoodsDetailOfOhFei(
							sLSHttpInterfaceInfo, originalGoodsId, areaServer,
							rechargeLimit);
					sLSHttpInterfaceInfo.setResMsg("SUCCESS");

				} else if ("20121001".equals(suppliersId)) { // 坚果网络
					sLSHttpInterfaceInfo = getGoodsDetailOfNutsNet(
							sLSHttpInterfaceInfo, originalGoodsId);
					sLSHttpInterfaceInfo.setResMsg("SUCCESS");

				} else if ("20121002".equals(suppliersId)) { // 腾讯
					sLSHttpInterfaceInfo = getGoodsDetailOfTencent(
							sLSHttpInterfaceInfo, originalGoodsId);
					sLSHttpInterfaceInfo.setResMsg("SUCCESS");
				} else if ("20121003".equals(suppliersId)) { // 恩联
					sLSHttpInterfaceInfo = getGoodsDetailOfEnLink(
							sLSHttpInterfaceInfo, originalGoodsId);
					sLSHttpInterfaceInfo.setResMsg("SUCCESS");
				} else if ("20121004".equals(suppliersId)) { // 星启天
					sLSHttpInterfaceInfo = XingQiTianTradeOfDeal
							.getGoodsDetailOfXing(sLSHttpInterfaceInfo,
									originalGoodsId, xingParvalueDAO,
									xingAccountTypeDAO, xingChargeTypeDAO,
									xingGameAreaSrvDAO);
					sLSHttpInterfaceInfo.setResMsg("SUCCESS");
				} else if ("20121005".equals(suppliersId)) {
					sLSHttpInterfaceInfo = getGoodsDetailOfJpay(
							sLSHttpInterfaceInfo, originalGoodsId);
					sLSHttpInterfaceInfo.setResMsg("SUCCESS");
				} else if ("20121006".equals(suppliersId)) { // 易百米
					sLSHttpInterfaceInfo = EBaiMiTradeDeal
							.getGoodsDetailOfEbaiMi(sLSHttpInterfaceInfo,
									originalGoodsId, eBaiMiDAO);
					sLSHttpInterfaceInfo.setResMsg("SUCCESS");
				} else if ("20121007".equals(suppliersId)) { // 7996

				} else if ("20121008".equals(suppliersId)) { // 沃谷
					sLSHttpInterfaceInfo = getGoodsDetailOfWogreat(
							sLSHttpInterfaceInfo, originalGoodsId);
					sLSHttpInterfaceInfo.setResMsg("SUCCESS");
				} else if ("20121009".equals(suppliersId)) { // 云恩
					sLSHttpInterfaceInfo = getGoodsDetailOfYun(
							sLSHttpInterfaceInfo, originalGoodsId);
					sLSHttpInterfaceInfo.setResMsg("SUCCESS");
				} else if ("20121010".equals(suppliersId)) { // 恩付
					sLSHttpInterfaceInfo = EnfuTradeDeal.getGoodsDetailOfEnfu(
							sLSHttpInterfaceInfo, originalGoodsId,
							enfuGoodsDetailDAO, enfuAreaDAO, enfuServerDAO);
				} else if ("20121011".equals(suppliersId)) { // 鑫合
					sLSHttpInterfaceInfo = xinHeTradeDeal
							.getGoodsDetailOfXinHe(sLSHttpInterfaceInfo,
									originalGoodsId);
					sLSHttpInterfaceInfo.setResMsg("SUCCESS");
				} else {
					//TODO 获取上游商品商品信息，返回下游
					String dealname = EKHInterfaceserviceImp
							.getDealName(suppliersId);
					if (dealname == null || "".equals(dealname)) {
						log.error("进入Service开始处理[" + head.getRequestId()
								+ "]的请求,无此供应商配置:"+suppliersId);
					} else {
						try {
							BaseDeal basedeal = (BaseDeal) StartMain.APPLICATION_CONTEXT
									.getBean(dealname);
							sLSHttpInterfaceInfo = basedeal
									.getGoodsDetail(sLSHttpInterfaceInfo,
											originalGoodsId, head);
						} catch (Exception e) {
							log.error("进入Service开始处理[" + head.getRequestId()
									+ "]的请求,供应商信息 查询异常:"+suppliersId+"|"+e);
						}
					}
				}
				String resultBody = gson.toJson(sLSHttpInterfaceInfo);
				return resultBody;
			}
		}
		return null;
	}

	/**
	 * 得到云恩产品详细
	 * 
	 * @param sLSHttpInterfaceInfo
	 * @param originalGoodsId
	 * @return
	 */
	private SLSHttpInterfaceInfo getGoodsDetailOfYun(
			SLSHttpInterfaceInfo sLSHttpInterfaceInfo, String originalGoodsId) {
		sLSHttpInterfaceInfo.setGameUnit("元");
		return sLSHttpInterfaceInfo;
	}

	/**
	 * 得到沃谷产品详细
	 * 
	 * @param sLSHttpInterfaceInfo
	 * @param originalGoodsId
	 * @return
	 */
	private SLSHttpInterfaceInfo getGoodsDetailOfWogreat(
			SLSHttpInterfaceInfo sLSHttpInterfaceInfo, String originalGoodsId) {
		WogreatProduct wp = this.wogreatDAO.queryByProId(originalGoodsId);
		List<WogreatAreaServer> asList = this.wogreatAsDAO
				.queryByProductId(originalGoodsId);
		List<String> bigAreaNameList = this.wogreatAsDAO
				.queryAreaNameByProductId(originalGoodsId);
		List<String> rechargeNameList = this.wogreatRechargeDAO
				.queryRechargeNameByProductId(originalGoodsId);
		List<String> AccNameList = this.wogreatAccountDAO
				.queryAccNameByProductId(originalGoodsId);
		StringBuilder areaServerName = new StringBuilder();
		StringBuilder rechName = new StringBuilder();
		StringBuilder accName = new StringBuilder();
		StringBuilder sb = new StringBuilder();
		if (bigAreaNameList != null && bigAreaNameList.size() > 0) {
			for (String bigAreaName : bigAreaNameList) {
				sb.append(bigAreaName);
				sb.append("&&");
			}
		}
		if (asList != null && asList.size() > 0) {
			for (WogreatAreaServer areaSerInfo : asList) {
				areaServerName.append(areaSerInfo.getAreaName());
				areaServerName.append("##");
				String smallServerName = areaSerInfo.getServerName();
				if (StringUtils.isNotEmpty(smallServerName)) {
					areaServerName.append(smallServerName);
				} else {
					areaServerName.append("null");
				}
				areaServerName.append("&&");
			}
		}
		if (rechargeNameList != null && rechargeNameList.size() > 0) {
			for (String reName : rechargeNameList) {
				rechName.append(reName);
				rechName.append("&&");
			}
		}
		if (AccNameList != null && AccNameList.size() > 0) {
			for (String aName : AccNameList) {
				accName.append(aName);
				accName.append("&&");
			}
		}
		String asName = areaServerName.toString();
		String areaNameStr = sb.toString();
		String rechNameStr = rechName.toString();
		String accountNameStr = accName.toString();
		String areaServer = null;
		String bigAreaName = null;
		String recharge = null;
		String account = null;
		if (asName != null && !("".equals(asName))) {
			areaServer = asName.substring(0, asName.length() - 2);
		}
		if (areaNameStr != null && !("".equals(areaNameStr))) {
			bigAreaName = areaNameStr.substring(0, areaNameStr.length() - 2);
		}
		if (rechNameStr != null && !("".equals(rechNameStr))) {
			recharge = rechNameStr.substring(0, rechNameStr.length() - 2);
		}
		if (accountNameStr != null && !("".equals(accountNameStr))) {
			account = accountNameStr.substring(0, accountNameStr.length() - 2);
		}
		StringBuilder strBui = new StringBuilder();
		strBui.append(recharge);
		strBui.append("##");
		if (wp != null) {
			String remark = wp.getRemark();
			if (StringUtils.isNotBlank(remark)) {
				strBui.append(remark);
			} else {
				strBui.append("null");
			}
		} else {
			strBui.append("null");
		}
		strBui.append("##");
		strBui.append("null");
		strBui.append("##");
		strBui.append("null");
		String chargeType = strBui.toString().trim();
		sLSHttpInterfaceInfo.setAccountType(account);
		sLSHttpInterfaceInfo.setChargeType(chargeType);
		sLSHttpInterfaceInfo.setGameServer(areaServer);
		sLSHttpInterfaceInfo.setGameArea(bigAreaName);
		sLSHttpInterfaceInfo.setGameUnit("元");
		return sLSHttpInterfaceInfo;
	}

	/**
	 * 获取捷易通产品详细信息
	 * 
	 * @param sLSHttpInterfaceInfo
	 * @param originalGoodsId
	 * @return
	 */
	private SLSHttpInterfaceInfo getGoodsDetailOfJpay(
			SLSHttpInterfaceInfo sLSHttpInterfaceInfo, String originalGoodsId) {
		JieyitongGoodsInfo jInfo = this.jpayGoodsDAO
				.queryByGoodsId(originalGoodsId);
		String remark = jInfo.getRemark();
		sLSHttpInterfaceInfo.setNoteinfo("提示：" + remark);

		List<JieyitongAreaServerInfo> asList = this.jpayAreaDAO
				.queryByGoodsId(originalGoodsId);
		StringBuilder sb = new StringBuilder();
		if (asList != null && asList.size() > 0) {
			for (JieyitongAreaServerInfo asInfo : asList) {
				sb.append(asInfo.getAreaName());
				sb.append("=");
				sb.append(asInfo.getAreaSrvCode());
				sb.append("&&");
			}
		}
		String areaNameStr = sb.toString();
		String bigAreaName = null;
		if (areaNameStr != null && !("".equals(areaNameStr))) {
			bigAreaName = areaNameStr.substring(0, areaNameStr.length() - 2);
		}
		sLSHttpInterfaceInfo.setGameArea2(bigAreaName);
		sLSHttpInterfaceInfo.setGameUnit("元");

		return sLSHttpInterfaceInfo;

	}

	/**
	 * 获取恩联商品的详细信息
	 * 
	 * @param sLSHttpInterfaceInfo
	 * @param originalGoodsId
	 * @return
	 */
	private SLSHttpInterfaceInfo getGoodsDetailOfEnLink(
			SLSHttpInterfaceInfo sLSHttpInterfaceInfo, String originalGoodsId) {
		EnLinkProduct enLinkProduct = this.enLinkProductDAO
				.queryByProductId(originalGoodsId);
		String t_remark = enLinkProduct.getT_remark();
		String remark = enLinkProduct.getRemark();
		if (StringUtils.isNotEmpty(remark)) {
			sLSHttpInterfaceInfo.setNoteinfo("提示：" + t_remark + "--" + remark);
		} else {
			sLSHttpInterfaceInfo.setNoteinfo("提示：" + t_remark);
		}
		List<EnlinkProductAreaServer> asList = this.enLinkAreaServerDAO
				.queryByProductId(originalGoodsId);
		List<String> bigAreaNameList = this.enLinkAreaServerDAO
				.queryAreaNameByProductId(originalGoodsId);
		StringBuilder strBuf = new StringBuilder();
		StringBuilder sb = new StringBuilder();
		if (bigAreaNameList != null && bigAreaNameList.size() > 0) {
			for (String bigAreaName : bigAreaNameList) {
				sb.append(bigAreaName);
				sb.append("&&");
			}
		}
		if (asList != null && asList.size() > 0) {
			for (EnlinkProductAreaServer areaSerInfo : asList) {
				strBuf.append(areaSerInfo.getBigAreaName());
				strBuf.append("##");
				String smallServerName = areaSerInfo.getSmallServerName();
				if (StringUtils.isNotEmpty(smallServerName)) {
					strBuf.append(smallServerName);
				} else {
					strBuf.append("null");
				}
				strBuf.append("&&");
			}
		}
		String str = strBuf.toString();
		String areaNameStr = sb.toString();
		String areaServer = null;
		String bigAreaName = null;
		if (str != null && !("".equals(str))) {
			areaServer = str.substring(0, str.length() - 2);
		}
		if (areaNameStr != null && !("".equals(areaNameStr))) {
			bigAreaName = areaNameStr.substring(0, areaNameStr.length() - 2);
		}
		StringBuilder strBui = new StringBuilder();
		strBui.append("null");
		strBui.append("##");
		strBui.append("1-100");
		strBui.append("##");
		strBui.append("null");
		strBui.append("##");
		strBui.append("null");
		String chargeType = strBui.toString().trim();
		sLSHttpInterfaceInfo.setChargeType(chargeType);
		sLSHttpInterfaceInfo.setGameServer(areaServer);
		sLSHttpInterfaceInfo.setGameArea(bigAreaName);
		sLSHttpInterfaceInfo.setGameUnit("元");

		return sLSHttpInterfaceInfo;
	}

	/**
	 * 得到腾讯商品的详细信息
	 * 
	 * @param sLSHttpInterfaceInfo
	 * @param originalGoodsId
	 * @return
	 */
	private SLSHttpInterfaceInfo getGoodsDetailOfTencent(
			SLSHttpInterfaceInfo sLSHttpInterfaceInfo, String originalGoodsId) {
		TencentGoodsInfo tencentGoodsInfo = null;
		tencentGoodsInfo = tencentGoodsInfoDAO
				.queryGoodsInfoGoodsId(originalGoodsId);
		// 可充值数量
		String num = tencentGoodsInfo.getNum();
		StringBuilder strBui = new StringBuilder();
		strBui.append("null");
		strBui.append("##");
		strBui.append(num);
		strBui.append("##");
		strBui.append("null");
		strBui.append("##");
		strBui.append("null");
		String chargeType = strBui.toString().trim();
		sLSHttpInterfaceInfo.setChargeType(chargeType);
		sLSHttpInterfaceInfo.setGameUnit("元");

		return sLSHttpInterfaceInfo;
	}

	/**
	 * 坚果网络商品详细
	 * 
	 * @param sLSHttpInterfaceInfo
	 * @param originalGoodsId
	 * @return
	 */
	@SuppressWarnings("unchecked")
	private SLSHttpInterfaceInfo getGoodsDetailOfNutsNet(
			SLSHttpInterfaceInfo sLSHttpInterfaceInfo, String originalGoodsId) {
		// 坚果网络商品详细访问Url
		String url = assembleNutsNetUrl(originalGoodsId);
		Map<String, Object> map = null;
		// 商品详细解析
		map = sendHttpRequestOfGoodsDetail(url, originalGoodsId);
		List<ChargeTypeInfo> chargetypeList = null;
		List<NutsNetGoodsAreaInfo> nutsNetGoodsAreaInfoList = null;
		List<NutsNetGoodsServerInfo> nutsNetGoodsServerInfoList = null;
		List<AccountTypeInfo> accountTypeInfoList = null;
		List<NutsNetGoodsDetailTop> goodsdetailTopList = null;
		// List<ChooseGemInfo> chooseGemInfoList = null;
		if (map != null) {
			chargetypeList = (List<ChargeTypeInfo>) map.get("chargetypeList");
			nutsNetGoodsAreaInfoList = (List<NutsNetGoodsAreaInfo>) map
					.get("nutsNetGoodsAreaInfoList");
			nutsNetGoodsServerInfoList = (List<NutsNetGoodsServerInfo>) map
					.get("nutsNetGoodsServerInfoList");
			accountTypeInfoList = (List<AccountTypeInfo>) map
					.get("accountTypeInfoList");
			goodsdetailTopList = (List<NutsNetGoodsDetailTop>) map
					.get("goodsdetailTopList");
			// chooseGemInfoList = (List<ChooseGemInfo>)
			// map.get("chooseGemInfoList");
		}

		if (chargetypeList != null && chargetypeList.size() > 0) {
			StringBuilder strBui = new StringBuilder();
			for (ChargeTypeInfo chargeTypeInfo : chargetypeList) {
				String chargeTypeName = chargeTypeInfo.getChargetypeName();
				if (chargeTypeName != null && !("".equals(chargeTypeName))) {
					strBui.append(chargeTypeName);
					strBui.append("##");
				} else {
					strBui.append("null");
					strBui.append("##");
				}

				String buynumber_list = chargeTypeInfo.getBuynumber_list();
				if (buynumber_list != null && !("".equals(buynumber_list))) {
					strBui.append(buynumber_list);
					strBui.append("##");
				} else {
					strBui.append("1"); // 默认是1个
					strBui.append("##");
				}

				String tbuynumber_list = chargeTypeInfo.getTbuynumber_list();
				if (tbuynumber_list != null && !("".equals(tbuynumber_list))) {
					strBui.append(tbuynumber_list);
					strBui.append("##");
				} else {
					strBui.append("null");
					strBui.append("##");
				}

				String tbuynumbername = chargeTypeInfo.getTbuynumbername();
				if (tbuynumbername != null && !("".equals(tbuynumbername))) {
					strBui.append(tbuynumbername);
				} else {
					strBui.append("null");
				}
				strBui.append("&&");
			}
			String value = strBui.toString().trim();
			String chargeType = value.substring(0, value.length() - 2);
			sLSHttpInterfaceInfo.setChargeType(chargeType);
		}

		if (nutsNetGoodsAreaInfoList != null
				&& nutsNetGoodsAreaInfoList.size() > 0) {
			StringBuilder strBui = new StringBuilder();
			int length = nutsNetGoodsAreaInfoList.size();
			if (length > 10) {
				length = 10;
			}

			for (int i = 0; i < length; i++) {
				NutsNetGoodsAreaInfo nutsNetGoodsAreaInfo = nutsNetGoodsAreaInfoList
						.get(i);
				String gameAreaName = nutsNetGoodsAreaInfo.getGameAreaName();
				if (gameAreaName != null && !("".equals(gameAreaName))) {
					strBui.append(gameAreaName);
				}
				strBui.append("&&");
			}

			String value = strBui.toString().trim();
			String gameAreaName = value.substring(0, value.length() - 2);
			sLSHttpInterfaceInfo.setGameArea(gameAreaName);
		}

		if (nutsNetGoodsServerInfoList != null
				&& nutsNetGoodsServerInfoList.size() > 0) {
			StringBuilder strBui = new StringBuilder();
			int length = nutsNetGoodsServerInfoList.size();
			if (length > 200) {
				length = 200;
			}
			for (int i = 0; i < length; i++) {
				NutsNetGoodsServerInfo nutsNetGoodsServerInfo = nutsNetGoodsServerInfoList
						.get(i);
				String gameAreaName = nutsNetGoodsServerInfo.getGameAreaName();
				if (gameAreaName != null && !("".equals(gameAreaName))) {
					strBui.append(gameAreaName);
					strBui.append("##");
				} else {
					strBui.append("null");
					strBui.append("##");
				}

				String gamesrvName = nutsNetGoodsServerInfo.getGamesrvName();
				if (gamesrvName != null && !("".equals(gamesrvName))) {
					strBui.append(gamesrvName);
				} else {
					strBui.append("null");
				}
				strBui.append("&&");
			}
			String value = strBui.toString().trim();
			String gameServerName = value.substring(0, value.length() - 2);
			sLSHttpInterfaceInfo.setGameServer(gameServerName);
		}

		if (accountTypeInfoList != null && accountTypeInfoList.size() > 0) {
			StringBuilder strBui = new StringBuilder();
			for (AccountTypeInfo accountTypeInfo : accountTypeInfoList) {
				String accountTypeName = accountTypeInfo.getAccountTypeName();
				if (accountTypeName != null && !("".equals(accountTypeName))) {
					strBui.append(accountTypeName);
				}
				strBui.append("&&");
			}
			String value = strBui.toString().trim();
			String accounttypeName = value.substring(0, value.length() - 2);
			sLSHttpInterfaceInfo.setAccountType(accounttypeName);
		}

		if (goodsdetailTopList != null && goodsdetailTopList.size() > 0) {
			NutsNetGoodsDetailTop topInfo = goodsdetailTopList.get(0);
			if (topInfo != null) {
				String noteinfo = topInfo.getNoteinfo();
				sLSHttpInterfaceInfo.setNoteinfo(noteinfo);
				String gameUntil = topInfo.getGameuntil();
				sLSHttpInterfaceInfo.setGameUnit(gameUntil);
			}
		}

		return sLSHttpInterfaceInfo;
	}

	/**
	 * 殴飞商品详细
	 * 
	 * @param sLSHttpInterfaceInfo
	 * @param originalGoodsId
	 * @param areaServer
	 * @param rechargeLimit
	 * @return
	 */
	private SLSHttpInterfaceInfo getGoodsDetailOfOhFei(
			SLSHttpInterfaceInfo sLSHttpInterfaceInfo, String originalGoodsId,
			String areaServer, String rechargeLimit) {
		// 根据原始产品Id，查询殴飞区服表
		List<OhFeiGoodsAreaServerInfo> list = null;
		list = ohFeiGoodsAreaServerDAO.queryByGoodsId(originalGoodsId);
		List<String> areaNameList = this.ohFeiGoodsAreaServerDAO
				.queryAreaNameByGoodsId(originalGoodsId);
		StringBuilder sb = new StringBuilder();
		StringBuilder strBuf = new StringBuilder();
		if (areaNameList != null && areaNameList.size() > 0) {
			for (String areaName : areaNameList) {
				sb.append(areaName);
				sb.append("&&");
			}
		}
		if (list != null && list.size() > 0) {
			for (OhFeiGoodsAreaServerInfo areaSerInfo : list) {
				strBuf.append(areaSerInfo.getArea());
				strBuf.append("##");
				if (StringUtils.isNotEmpty(areaSerInfo.getServer())) {
					strBuf.append(areaSerInfo.getServer());
				} else {
					strBuf.append("null");
				}
				strBuf.append("&&");
			}
		}

		String areaName = null;
		String areaNameStr = sb.toString();
		String str = strBuf.toString();
		if (areaNameStr != null && !("".equals(areaNameStr))) {
			areaName = areaNameStr.substring(0, areaNameStr.length() - 2);
		}
		if (str != null && !("".equals(str))) {
			areaServer = str.substring(0, str.length() - 2);
		}

		sLSHttpInterfaceInfo.setGameArea(areaName);
		sLSHttpInterfaceInfo.setGameServer(areaServer);

		// 根据原始产品Id，查询殴飞产品表
		OhFeiGoodsInfo ohFeiGoodsInfo = null;
		ohFeiGoodsInfo = ohFeiGoodsInfoDAO.queryById(originalGoodsId);
		if (ohFeiGoodsInfo != null) {
			rechargeLimit = ohFeiGoodsInfo.getAmounts();
		}
		StringBuilder strBui = new StringBuilder();
		strBui.append("null");
		strBui.append("##");

		if (rechargeLimit != null && !("".equals(rechargeLimit))) {
			strBui.append(rechargeLimit);
			strBui.append("##");
		} else {
			strBui.append("1"); // 默认是1个
			strBui.append("##");
		}
		strBui.append("null");
		strBui.append("##");
		strBui.append("null");
		String chargeType = strBui.toString().trim();
		sLSHttpInterfaceInfo.setChargeType(chargeType);
		sLSHttpInterfaceInfo.setGameUnit("张");

		return sLSHttpInterfaceInfo;
	}

	/**
	 * 检查下游所传的订单总价是否正确
	 * 
	 * @param info
	 * @param goodsSupplyManageInfo
	 * @return
	 */
	protected boolean checkTotalPrice(SLSHttpInterfaceInfo info,
			GoodsSupplyManageInfo goodsSupplyManageInfo) {
		boolean flag = true;
		String totalPrice = info.getTotalPrice();
		int totalPriceVal = DataConversion.converStringToInteger(totalPrice);

		String chargeTypeName = info.getChargeTypeName();
		if (chargeTypeName != null && !("".equals(chargeTypeName))) {
			String originalGoodsId = goodsSupplyManageInfo.getOriginalGoodsId();
			String totalPriceStr = DeductionRefund.calculateTotalPrice(info,
					chargeTypeName, originalGoodsId, chargeTypeInfoDAO);
			int totalPriceStrVal = DataConversion
					.converStringToInteger(totalPriceStr);
			if (totalPriceVal < totalPriceStrVal) {
				flag = false;
			}
		}

		return flag;
	}

	/**
	 * 合作方用户不存在
	 * 
	 * @return
	 * @date 2012-11-20
	 */
	protected String returnUserNotExist() {
		SLSHttpInterfaceInfo sLSHttpInterfaceInfo = new SLSHttpInterfaceInfo();
		sLSHttpInterfaceInfo.setResMsg("FAILED");
		sLSHttpInterfaceInfo.setFailedCode("104");
		sLSHttpInterfaceInfo.setFailedReason("合作方用户不存在");
		String resultBody = null;
		resultBody = gson.toJson(sLSHttpInterfaceInfo);
		return resultBody;
	}

	/**
	 * 检查库存不足
	 * 
	 * @return
	 * @date 2012-11-20
	 */
	protected String checkReserveShortage() {
		SLSHttpInterfaceInfo sLSHttpInterfaceInfo = new SLSHttpInterfaceInfo();
		sLSHttpInterfaceInfo.setResMsg("FAILED");
		sLSHttpInterfaceInfo.setFailedCode("207");
		sLSHttpInterfaceInfo.setFailedReason("商品库存不足");
		String resultBody = null;
		resultBody = gson.toJson(sLSHttpInterfaceInfo);
		return resultBody;
	}

	/**
	 * 订单重复提交
	 * 
	 * @return
	 * @date 2012-11-20
	 */
	protected String submitOrderRepeat() {
		SLSHttpInterfaceInfo sLSHttpInterfaceInfo = new SLSHttpInterfaceInfo();
		sLSHttpInterfaceInfo.setResMsg("FAILED");
		sLSHttpInterfaceInfo.setFailedCode("502");
		sLSHttpInterfaceInfo.setFailedReason("该订单已存在");
		String resultBody = null;
		resultBody = gson.toJson(sLSHttpInterfaceInfo);
		return resultBody;
	}

	/**
	 * 支付失败时的操作
	 * 
	 * @param orderTime
	 * @param paymentOrderNo
	 * @param orderId
	 * @param head
	 * @param info
	 * @return
	 * @date 2012-11-20
	 */
	protected String operatePayFailure(String orderTime, String paymentOrderNo,
			String orderId, Head head, SLSHttpInterfaceInfo info) {
		GoodsOrderInfo goodsOrderInfo1 = new GoodsOrderInfo();
		goodsOrderInfo1.setIsPay("0"); // 0：支付失败 1：支付成功
		goodsOrderInfo1.setPayTime(orderTime);
		goodsOrderInfo1.setPaymentOrderNo(paymentOrderNo);
		goodsOrderInfo1.setStatus("0");
		try {
			updateGoodsOrder(orderId, head, goodsOrderInfo1);
		} catch (Exception e) {
			log.error("请求ID：" + head.getRequestId() + "根据支付失败状态更新订单异常！", e);
			throw new ServerDisponseException(
					ExceptionCodeDes.ACCESS_DATABASE_ERROR.getCode(),
					ExceptionCodeDes.ACCESS_DATABASE_ERROR.getDescription());
		}

		// 返回给上层对象
		SLSHttpInterfaceInfo sLSHttpInterfaceInfo = new SLSHttpInterfaceInfo();
		sLSHttpInterfaceInfo.setResMsg("FAILED");
		sLSHttpInterfaceInfo.setFailedCode("201");
		sLSHttpInterfaceInfo.setFailedReason("支付失败");
		sLSHttpInterfaceInfo.setPtOrderNo(info.getPtOrderNo());
		sLSHttpInterfaceInfo.setStatus("ORDER_FAILED");
		sLSHttpInterfaceInfo.setSupOrderNo(orderId);
		String resultBody = null;
		resultBody = gson.toJson(sLSHttpInterfaceInfo);
		return resultBody;
	}

	/**
	 * 支付成功时的操作
	 * 
	 * @param orderTime
	 * @param paymentOrderNo
	 * @param orderId
	 * @param head
	 * @param goodsSupplyManageInfo
	 * @param info
	 * @return
	 * @date 2012-11-20
	 */
	protected String operatePaySuccess(String orderTime, String paymentOrderNo,
			String orderId, Head head,
			GoodsSupplyManageInfo goodsSupplyManageInfo,
			SLSHttpInterfaceInfo info, boolean isBuyCard, String merchantIP) {
		GoodsOrderInfo goodsOrderInfo1 = new GoodsOrderInfo();
		goodsOrderInfo1.setIsPay("1"); // 0：支付失败
										// 1：支付成功
		goodsOrderInfo1.setPayTime(orderTime);
		goodsOrderInfo1.setPaymentOrderNo(paymentOrderNo);
		try {
			updateGoodsOrder(orderId, head, goodsOrderInfo1);
		} catch (Exception e) {
			log.error("请求ID：" + head.getRequestId() + "根据支付成功状态更新订单异常！", e);
			throw new ServerDisponseException(
					ExceptionCodeDes.ACCESS_DATABASE_ERROR.getCode(),
					ExceptionCodeDes.ACCESS_DATABASE_ERROR.getDescription());
		}

		// 供应商编号
		String supplyId = goodsSupplyManageInfo.getSuppliersId();
		// 原始商品Id
		String originalGoodsId = goodsSupplyManageInfo.getOriginalGoodsId();
		String resultBody = null;
		// 调用上游供货商接口
		resultBody = invokeUpstreamSupply(supplyId, info, originalGoodsId,
				orderId, head, orderTime, paymentOrderNo, isBuyCard, merchantIP);
		return resultBody;
	}

	/**
	 * 调用供货商上游接口
	 * 
	 * @param supplyId
	 * @param info
	 * @param originalGoodsId
	 * @param orderId
	 * @param head
	 * @param orderTime
	 * @param paymentOrderNo
	 * @return
	 */
	private String invokeUpstreamSupply(String supplyId,
			SLSHttpInterfaceInfo info, String originalGoodsId, String orderId,
			Head head, String orderTime, String paymentOrderNo,
			boolean isBuyCard, String merchantIP) {
		String resultBody = null;
		if ("20121000".equals(supplyId)) { // 殴飞
			if (isBuyCard) { // 提卡
				resultBody = obtainOhFeiCardGoods(info, originalGoodsId,
						orderId, head, orderTime, paymentOrderNo);
			} else { // 直充
				resultBody = dealTradeResultOfOhFei(info, originalGoodsId,
						orderId, head, orderTime, paymentOrderNo);
			}
			return resultBody;

		} else if ("20121001".equals(supplyId)) { // 坚果网络
			resultBody = dealTradeResultOfNutsNet(info, originalGoodsId,
					orderId, head, orderTime, paymentOrderNo);
			return resultBody;

		} else if ("20121002".equals(supplyId)) { // 腾讯
			resultBody = tencentService.saveTradeOfTencent(info,
					originalGoodsId, orderId, head, orderTime, paymentOrderNo,
					merchantIP, gson);
			return resultBody;
		} else if ("20121003".equals(supplyId)) {// 恩联
			resultBody = dealTradeResultOfEnLink(info, originalGoodsId,
					orderId, head, orderTime, paymentOrderNo, merchantIP);
			return resultBody;
		} else if ("20121004".equals(supplyId)) { // 星启天
			SLSHttpInterfaceInfo sLSHttpInterfaceInfo = XingQiTianTradeOfDeal
					.dealTradeResultOfXingQiTian(info, originalGoodsId,
							orderId, head, orderTime, paymentOrderNo,
							xingParvalueDAO, xingChargeTypeDAO,
							xingAccountTypeDAO, xingGameAreaSrvDAO,
							chargeTypeInfoDAO, goodsOrderDAO,
							downstreamUserDAO, goodsOrderLogDAO,
							goodsInfoManageDAO, specialPriceSystemDAO);
			resultBody = gson.toJson(sLSHttpInterfaceInfo);
			return resultBody;
		} else if ("20121005".equals(supplyId)) { // 捷易通
			resultBody = JpayTradeDeal.dealTradeResultOfJpay(info,
					originalGoodsId, orderId, orderTime, paymentOrderNo, head,
					goodsOrderDAO, goodsSupplyManageDAO, jpayGoodsDAO,
					jpayAreaDAO, downstreamUserDAO);
			return resultBody;
		} else if ("20121006".equals(supplyId)) { // 易百米
			if (isBuyCard) {
				// 提卡
				resultBody = EBaiMiTradeDeal.dealGetCardResultOfEBaiMi(info,
						originalGoodsId, orderId, orderTime, paymentOrderNo,
						head, goodsOrderDAO, goodsSupplyManageDAO, eBaiMiDAO,
						downstreamUserDAO);
			} else {
				// // 直充
				// resultBody = EBaiMiTradeDeal.dealTradeResultOfEBaiMi(info,
				// originalGoodsId, orderId, orderTime, paymentOrderNo,
				// head, goodsOrderDAO, goodsSupplyManageDAO, eBaiMiDAO,
				// downstreamUserDAO);

				// 支付宝直充
				resultBody = EBaiMiTradeDeal.dealTradeOfZhifubao(info, orderId,
						orderTime, paymentOrderNo, head, goodsOrderDAO,
						goodsSupplyManageDAO, downstreamUserDAO);

				return resultBody;
			}
			return resultBody;
		} else if ("20121007".equals(supplyId)) {// 7996
			resultBody = SevenNineNineSixTradeDeal.dealTradeResultOfSnns(info,
					originalGoodsId, orderId, orderTime, paymentOrderNo, head,
					goodsOrderDAO, goodsSupplyManageDAO, snnsDAO,
					downstreamUserDAO);
			return resultBody;
		} else if ("20121008".equals(supplyId)) {// 沃谷
			resultBody = WogreatTradeDeal.dealTradeResultOfWogreat(info,
					originalGoodsId, orderId, orderTime, paymentOrderNo, head,
					goodsOrderDAO, goodsSupplyManageDAO, downstreamUserDAO,
					wogreatAccountDAO, wogreatRechargeDAO, wogreatAsDAO,
					merchantIP, null, null, null);
			return resultBody;
		} else if ("20121009".equals(supplyId)) {// 云恩
			resultBody = YunEnTradeDeal.dealTradeResultOfYun(info,
					originalGoodsId, orderId, paymentOrderNo, orderTime, head,
					goodsOrderDAO, goodsSupplyManageDAO, downstreamUserDAO,
					merchantIP);
			return resultBody;
		} else if ("20121010".equals(supplyId)) {// 恩付
			resultBody = EnfuTradeDeal.dealTradeOfEnfu(info, originalGoodsId,
					orderId, head, orderTime, enfuGoodsDAO, enfuAccountTypeDAO,
					enfuChargeTypeDAO, enfuAreaDAO, enfuChoosegemDAO,
					enfuServerDAO, goodsOrderDAO, goodsOrderLogDAO,
					downstreamUserDAO, goodsInfoManageDAO,
					specialPriceSystemDAO, paymentOrderNo, enfuGoodsDetailDAO,
					merchantIP, goodsSupplyManageDAO);
			return resultBody;
		} else if ("20121011".equals(supplyId)) {// 鑫合
			resultBody = xinHeTradeDeal.dealTradeResultOfXinHe(info, orderId,
					paymentOrderNo, orderTime, merchantIP, originalGoodsId,
					head);
			return resultBody;
		} else {
			// TODO
			String dealname = EKHInterfaceserviceImp.getDealName(supplyId);
			if (dealname == null || "".equals(dealname)) {
				return null;
			}

			GoodsOrderInfo orderInfo = new GoodsOrderInfo();
			GoodsSupplyManageInfo goodsinfo = new GoodsSupplyManageInfo();

			orderInfo.setOrderId(orderId);
			orderInfo.setPaymentOrderNo(paymentOrderNo);
//			orderInfo.setPayTime(orderTime);
			orderInfo.setMerchantIP(merchantIP);
			orderInfo.setSupplyId(supplyId);

			goodsinfo.setOriginalGoodsId(originalGoodsId);

			SLSHttpInterfaceInfo interfaceinfo = ekhinterface.insertTradeSupply(info,
					orderInfo, head, goodsinfo);

			resultBody = gson.toJson(interfaceinfo);
			return resultBody;
		}

		// return null;
	}

	/**
	 * 恩联充值返回结果处理
	 * 
	 * @param info
	 * @param originalGoodsId
	 * @param orderId
	 * @param head
	 * @param orderTime
	 * @param paymentOrderNo
	 * @return
	 * @throws UnsupportedEncodingException
	 */
	private String dealTradeResultOfEnLink(SLSHttpInterfaceInfo info,
			String originalGoodsId, String orderId, Head head,
			String orderTime, String paymentOrderNo, String merchantIP) {
		EnLinkTradeInfo resInfo = null;
		// 调用交易方法
		resInfo = tradeOfEnLink(info, originalGoodsId, orderId, head,
				orderTime, merchantIP);
		// 返回给上层对象
		SLSHttpInterfaceInfo sLSHttpInterfaceInfo = new SLSHttpInterfaceInfo();

		if (resInfo != null) {
			// 如果成功将为000000，失败为999999，充值中为222222,
			// 只能当状态为999999时，商户才可以退款给用户。
			String resultCode = resInfo.getResultCode();
			if ("222222".equals(resultCode)) { // 处理中
				sLSHttpInterfaceInfo.setResMsg("SUCCESS");
				sLSHttpInterfaceInfo.setPtOrderNo(info.getPtOrderNo());
				sLSHttpInterfaceInfo.setStatus("ORDER_UNDERWAY");
				sLSHttpInterfaceInfo.setSupOrderNo(orderId);
			} else if ("000000".equals(resultCode)) { // 成功
				sLSHttpInterfaceInfo.setResMsg("SUCCESS");
				sLSHttpInterfaceInfo.setPtOrderNo(info.getPtOrderNo());
				sLSHttpInterfaceInfo.setStatus("ORDER_SUCCESS");
				sLSHttpInterfaceInfo.setSupOrderNo(orderId);
			} else if ("999999".equals(resultCode)) { // 失败
				sLSHttpInterfaceInfo.setResMsg("FAILED");
				sLSHttpInterfaceInfo.setFailedCode("208");
				sLSHttpInterfaceInfo.setFailedReason("充值失败");
				sLSHttpInterfaceInfo.setPtOrderNo(info.getPtOrderNo());
				sLSHttpInterfaceInfo.setStatus("ORDER_FAILED");
				sLSHttpInterfaceInfo.setSupOrderNo(orderId);

				// 更新订单
				GoodsOrderInfo goodsOrderInfo1 = new GoodsOrderInfo();
				DeductionRefundInfo dedInfo = null;
				String paymentStatus = "";
				// 退款
				dedInfo = DeductionRefund.invokeDeductRefund(info, orderId,
						"1", orderTime, paymentOrderNo, head, goodsOrderDAO);
				if (dedInfo != null) {
					paymentStatus = dedInfo.getPaymentStatus();
				}
				if ("1".equals(paymentStatus)) { // 成功
					goodsOrderInfo1.setIsPay("3"); // 退款成功
					// 退款成功，通知下游用户
					DeductionRefund.noticeUserRefundMsg(orderId, dedInfo,
							goodsOrderDAO, downstreamUserDAO, goodsOrderLogDAO);

				} else if ("2".equals(paymentStatus)) {
					goodsOrderInfo1.setIsPay("2"); // 退款失败
				}
				try {
					updateGoodsOrder(orderId, head, goodsOrderInfo1);
				} catch (Exception e) {
					log.error(e);
					throw new ServerDisponseException(
							ExceptionCodeDes.ACCESS_DATABASE_ERROR.getCode(),
							ExceptionCodeDes.ACCESS_DATABASE_ERROR
									.getDescription());
				}
			}
		}
		sLSHttpInterfaceInfo.setGameAccount(info.getGameAccount());
		sLSHttpInterfaceInfo.setUnitPrice(info.getUnitPrice());
		sLSHttpInterfaceInfo.setBuyNum(info.getBuyNum());
		sLSHttpInterfaceInfo.setTotalPrice(info.getTotalPrice());

		String resultBody = null;
		resultBody = gson.toJson(sLSHttpInterfaceInfo);

		return resultBody;
	}

	/**
	 * 恩联交易
	 * 
	 * @param info
	 * @param originalGoodsId
	 * @param orderId
	 * @param head
	 * @param orderTime
	 * @return
	 * @throws UnsupportedEncodingException
	 */
	private EnLinkTradeInfo tradeOfEnLink(SLSHttpInterfaceInfo info,
			String originalGoodsId, String orderId, Head head,
			String orderTime, String merchantIP) {
		// if ("QQ00019".equals(originalGoodsId)) { // ===============Q币按元充值
		// // 省份名称
		// String province = IPAddressResolution.parseIPAddress(merchantIP);
		// if ("江苏".equals(province)) {
		// // 调用腾讯接口
		// String oriGoodsId = "100000001";
		// EnLinkTradeInfo resInfo = getTencentResInfo(info,
		// originalGoodsId, orderId, head, oriGoodsId);
		// return resInfo;
		// } else if ("河南".equals(province)) {
		// // 调用腾讯接口
		// String oriGoodsId = "100000002";
		// EnLinkTradeInfo resInfo = getTencentResInfo(info,
		// originalGoodsId, orderId, head, oriGoodsId);
		// return resInfo;
		// } else if ("湖北".equals(province)) {
		// // 调用腾讯接口
		// String oriGoodsId = "100000003";
		// EnLinkTradeInfo resInfo = getTencentResInfo(info,
		// originalGoodsId, orderId, head, oriGoodsId);
		// return resInfo;
		// } else if ("山东".equals(province)) {
		// // 调用腾讯接口
		// String oriGoodsId = "100000004";
		// EnLinkTradeInfo resInfo = getTencentResInfo(info,
		// originalGoodsId, orderId, head, oriGoodsId);
		// return resInfo;
		// } else if ("湖南".equals(province)) {
		// // 调用腾讯接口
		// String oriGoodsId = "100000005";
		// EnLinkTradeInfo resInfo = getTencentResInfo(info,
		// originalGoodsId, orderId, head, oriGoodsId);
		// return resInfo;
		// } else if ("广东".equals(province)) {
		// // 调用腾讯接口
		// String oriGoodsId = "100000006";
		// EnLinkTradeInfo resInfo = getTencentResInfo(info,
		// originalGoodsId, orderId, head, oriGoodsId);
		// return resInfo;
		// } else {
		// EnLinkTradeInfo resInfo = getEnLinkResInfo(info,
		// originalGoodsId, orderId, head, orderTime, merchantIP);
		// return resInfo;
		// }

		// } else { // ===================其他游戏充值产品
		EnLinkTradeInfo resInfo = getEnLinkResInfo(info, originalGoodsId,
				orderId, head, orderTime, merchantIP);
		return resInfo;
		// }
	}

	/**
	 * 调用腾讯充值接口返回信息解析
	 * 
	 * @param info
	 * @param originalGoodsId
	 * @param orderId
	 * @param head
	 * @param oriGoodsId
	 * @date 2013-04-22
	 * @return
	 */
	// private EnLinkTradeInfo getTencentResInfo(SLSHttpInterfaceInfo info,
	// String originalGoodsId, String orderId, Head head, String oriGoodsId) {
	// // String url = assembleParaUrlOfTencent(info, oriGoodsId, orderId,
	// head);
	// TencentGoodsInfo tencentGoodsInfo = null;
	// // tencentGoodsInfo = sendHttpRequestOfTencent(url, head);
	//
	// // String tran_seq = tencentGoodsInfo.getTran_seq(); //手拉手订单号
	// String ret = tencentGoodsInfo.getRet() + ""; // 返回码
	// // String in_acct = tencentGoodsInfo.getIn_acct(); //Q币充值账号
	// String num = tencentGoodsInfo.getNum() + ""; // 购买数量
	//
	// EnLinkTradeInfo enLinkInfo = new EnLinkTradeInfo();
	// enLinkInfo.setProdCode(originalGoodsId);
	// enLinkInfo.setProdNum(num);
	//
	// String status = "2";
	// String orderResult = "222222";
	// // 上游平台充值成功时间
	// String supOrderSuccessTime = null;
	// if ("0".equals(ret)) { // 成功
	// status = "1";
	// orderResult = "000000";
	// supOrderSuccessTime = ServerDateAndTime.getNowDateTime();
	// enLinkInfo.setResultCode("000000");
	// } else { // 处理中
	// status = "2";
	// orderResult = "222222";
	// enLinkInfo.setResultCode("222222");
	// }
	//
	// GoodsOrderInfo goodsOrderInfo = new GoodsOrderInfo();
	// goodsOrderInfo.setStatus(status);
	// goodsOrderInfo.setSupOrderSuccessTime(supOrderSuccessTime);
	// goodsOrderInfo.setResult(orderResult);
	// try {
	// // 根据交易返回的结果更新订单表
	// updateGoodsOrder(orderId, head, goodsOrderInfo);
	// } catch (Exception e) {
	// log.error("请求ID：" + head.getRequestId() + "根据来找卡返回的结果更新订单异常！", e);
	// throw new ServerDisponseException(
	// ExceptionCodeDes.ACCESS_DATABASE_ERROR.getCode(),
	// ExceptionCodeDes.ACCESS_DATABASE_ERROR.getDescription());
	// }
	//
	// return enLinkInfo;
	// }

	/**
	 * 获取恩联处理结果
	 * 
	 * @param info
	 * @param originalGoodsId
	 * @param orderId
	 * @param head
	 * @param orderTime
	 * @param merchantIP
	 * @date 2013-04-22
	 * @return
	 */
	private EnLinkTradeInfo getEnLinkResInfo(SLSHttpInterfaceInfo info,
			String originalGoodsId, String orderId, Head head,
			String orderTime, String merchantIP) {
		EnLinkTradeInfo resInfo = null;
		String paraStr = assembleParameterOfEnLinkTrade(info, originalGoodsId,
				orderId, orderTime, merchantIP);
		// 从xml配置文件中读取访问地址
		String address = PropertiesUtil.getValue("enlink.interface.address",
				"enlink.properties");

		// 发送http请求
		resInfo = sendHttpRequestOfEnLinkDirectTrade(address, paraStr, head);
		// 上游订单结果
		String orderResult = "";
		// 上游订单号
		String supOrderNo = "";
		// 上游平台充值成功时间
		String supOrderSuccessTime = "";
		if (resInfo != null) {
			// 订单结果
			orderResult = resInfo.getResultCode();
			// 上游平台订单号
			supOrderNo = resInfo.getTranaNo();
			supOrderSuccessTime = resInfo.getTime();
		}

		String status = "2";
		if ("222222".equals(orderResult)) { // 处理中
			status = "2";
		} else if ("000000".equals(orderResult)) { // 成功
			status = "1";
		} else if ("999999".equals(orderResult)) { // 充值失败
			status = "0";
		} else {
			status = "3"; // 存疑
		}

		GoodsOrderInfo goodsOrderInfo = new GoodsOrderInfo();
		goodsOrderInfo.setStatus(status);
		goodsOrderInfo.setSupOrderId(supOrderNo);
		goodsOrderInfo.setSupOrderSuccessTime(supOrderSuccessTime);
		goodsOrderInfo.setResult(orderResult);
		try {
			// 根据交易返回的结果更新订单表
			updateGoodsOrder(orderId, head, goodsOrderInfo);
		} catch (Exception e) {
			log.error("请求ID：" + head.getRequestId() + "根据来找卡返回的结果更新订单异常！", e);
			throw new ServerDisponseException(
					ExceptionCodeDes.ACCESS_DATABASE_ERROR.getCode(),
					ExceptionCodeDes.ACCESS_DATABASE_ERROR.getDescription());
		}

		return resInfo;
	}

	/**
	 * 拼接请求参数
	 * 
	 * @param info
	 * @param originalGoodsId
	 * @param orderId
	 * @param orderTime
	 * @return
	 * @throws UnsupportedEncodingException
	 */
	private String assembleParameterOfEnLinkTrade(SLSHttpInterfaceInfo info,
			String originalGoodsId, String orderId, String orderTime,
			String merchantIP) {
		String partner = PropertiesUtil.getValue("enlink.interface.partner",
				"enlink.properties");
		if (StringUtils.isNotEmpty(partner)) {
			partner = partner.trim();
		}
		String prodCode = originalGoodsId;
		String userName = PropertiesUtil.getValue("user.name",
				"enlink.properties");
		String userAccount = info.getGameAccount();
		String time = orderTime;
		String prodNum = info.getBuyNum();
		// returnUrl从配置文件中读取
		String returnUrl = PropertiesUtil.getValue("return.url",
				"enlink.properties");
		if (StringUtils.isNotEmpty(returnUrl)) {
			returnUrl = returnUrl.trim();
		}
		String gameArea = info.getGameArea();
		String gameServer = info.getGameServer();
		try {
			if (StringUtils.isNotEmpty(userAccount)) {
				userAccount = URLEncoder.encode(userAccount, "UTF-8");
			}
			if (StringUtils.isNotEmpty(gameArea)) {
				gameArea = URLEncoder.encode(gameArea, "UTF-8");
			}
			if (StringUtils.isNotEmpty(gameServer)) {
				gameServer = URLEncoder.encode(gameServer, "UTF-8");
			}
		} catch (UnsupportedEncodingException e) {
			log.error("中文编码异常！", e);
		}
		// String clientIp = info.getClientIp();
		// String clientIp = generateDycIp();
		String t_mark = "";
		String md5_key = PropertiesUtil.getValue("enlink.md5.key",
				"enlink.properties");
		if (StringUtils.isNotEmpty(md5_key)) {
			md5_key = md5_key.trim();
		}
		String sign = null;
		String data = merchantIP;
		data += "|";
		data += orderId;
		data += "|";
		if (StringUtils.isNotEmpty(gameArea)) {
			data += gameArea;
			data += "|";
		}
		if (StringUtils.isNotEmpty(gameServer)) {
			data += gameServer;
			data += "|";
		}
		data = data + partner + "|" + prodCode + "|" + prodNum + "|";
		if (StringUtils.isNotEmpty(returnUrl)) {
			data += returnUrl;
			data += "|";
		}
		data = data + time + "|" + userAccount + "|" + userName + "|" + md5_key;
		sign = UtilMD5Encryption.createMD5Encryption(data);
		sign = UtilMD5Encryption.createMD5Encryption(sign + "|" + md5_key);
		EnLinkRequestTradeInfo reqInfo = new EnLinkRequestTradeInfo();
		reqInfo.setForginOrderNo(orderId);
		reqInfo.setPartner(partner);
		reqInfo.setClientIp(merchantIP);
		reqInfo.setProdCode(prodCode);
		reqInfo.setProdNum(prodNum);
		reqInfo.setGameArea(gameArea);
		reqInfo.setGameServer(gameServer);
		reqInfo.setTime(time);
		reqInfo.setReturnUrl(returnUrl);
		reqInfo.setUserAccount(userAccount);
		reqInfo.setUserName(userName);
		reqInfo.setT_mark(t_mark);
		reqInfo.setSign(sign);
		String parameter = gson.toJson(reqInfo);

		log.info("发送给来找卡的http请求内容：" + "\n接口编号:" + partner + "\n订单提交时间:" + time
				+ "\nMD5签名串:" + sign + "\n用户账户:" + userName + "\n充值的账号:"
				+ userAccount + "\n产品编码:" + prodCode + "\n购买数量:" + prodNum
				+ "\n回调地址:" + returnUrl + "\n游戏大区:" + gameArea + "\n游戏服务器:"
				+ gameServer + "\n最终购买用户IP：" + merchantIP + "\n扩展字段:" + t_mark);
		return parameter;
	}

	public static String ips = "60.162,60.176,61.130,61.164,125.104,220.184,61.130,61.164,61.175,125.127";

	public static String generateDycIp() {
		String[] iparray = ips.split(",");
		int random1 = (int) (Math.random() * 10);
		String random2 = String.valueOf((int) (Math.random() * 255));
		String random3 = String.valueOf((int) (Math.random() * 255));
		return iparray[random1] + "." + random2 + "." + random3;
	}

	// public static void main(String[]a)
	// {
	// for(int i=0;i<100;i++)
	// System.out.println(generateDycIp());
	// }

	/**
	 * 发送http请求
	 * 
	 * @param url
	 * @param paraStr
	 * @return
	 */
	private EnLinkTradeInfo sendHttpRequestOfEnLinkDirectTrade(String address,
			String paraStr, Head head) {
		HttpClient httpClient = new HttpClient();
		EnLinkTradeInfo resInfo = null;
		try {
			// 对返回的gson格式字符串数据进行解析
			Map<String, String> map = new HashMap<String, String>();
			map.put("parameter", paraStr);
			log.info("请求ID：" + head.getRequestId() + "--发送到来找卡的请求参数：" + paraStr);
			String gsonStr = httpClient.doPost(address, map);
			log.info("请求ID：" + head.getRequestId() + "--来找卡返回给手拉手的请求结果："
					+ gsonStr);
			if (StringUtils.isNotEmpty(gsonStr)) {
				resInfo = gson.fromJson(gsonStr, EnLinkTradeInfo.class);
				return resInfo;
			}
		} catch (Exception e) {
			log.error("请求ID：" + head.getRequestId() + "--来找卡直充交易请求异常！", e);
			throw new ServerDisponseException(
					ExceptionCodeDes.HTTP_URL_FAILED.getCode(),
					ExceptionCodeDes.HTTP_URL_FAILED.getDescription());
		}
		return null;
	}

	/**
	 * 去供货表查询供货商品
	 * 
	 * @param goodsId
	 * @param head
	 * @return
	 */
	protected GoodsSupplyManageInfo checkSupplyGoods(String goodsId, Head head) {
		List<GoodsSupplyManageInfo> supplyList = null;
		GoodsSupplyManageInfo goodsSupplyManageInfo = null;
		try {
			// 去供货表查询供货商品
			GoodsSupplyManageInfo goodsSupplyManageInfo1 = new GoodsSupplyManageInfo();
			goodsSupplyManageInfo1.setGoodsId(goodsId);
			goodsSupplyManageInfo1.setGoodsState("1"); // 上架
			// 查询价格最低的供货商
			supplyList = goodsSupplyManageDAO
					.queryMininunPrice(goodsSupplyManageInfo1);
			if (supplyList != null && supplyList.size() > 0) {
				goodsSupplyManageInfo = supplyList.get(0);
			}
		} catch (Exception e) {
			log.error("Service处理[" + head.getRequestId() + "]的请求出现异常！", e);
			throw new ServerDisponseException(
					ExceptionCodeDes.ACCESS_DATABASE_ERROR.getCode(),
					ExceptionCodeDes.ACCESS_DATABASE_ERROR.getDescription());
		}

		return goodsSupplyManageInfo;
	}

	/**
	 * 获取手拉手订单号
	 * 
	 * @return
	 */
	protected String getSlsOrderNo() {
		String orderId = null;
		for (int s = 0; s < 10; s++) {
			if (orderId == null) {
				try {
					int port = 3838;
					try {
						port = Integer.parseInt(orderPort);
					} catch (Exception e) {
						log.error(e);
						throw new ServerDisponseException(
								ExceptionCodeDes.OBTAIN_ORDER_FAILURE.getCode(),
								ExceptionCodeDes.OBTAIN_ORDER_FAILURE
										.getDescription());
					}
					orderId = OrderIdServer.sendMessage(orderIp, port, this
							.getClass().getSimpleName());
					if (orderId == null)
						Thread.sleep(200);
				} catch (Exception e) {
					log.error(e);
					throw new ServerDisponseException(
							ExceptionCodeDes.OBTAIN_ORDER_FAILURE.getCode(),
							ExceptionCodeDes.OBTAIN_ORDER_FAILURE
									.getDescription());
				}
			} else
				break;
		}

		return orderId;
	}

	/**
	 * 坚果网络充值返回结果处理
	 * 
	 * @param info
	 * @param originalGoodsId
	 * @param orderId
	 * @param head
	 * @param orderTime
	 * @param paymentOrderNo
	 * @return
	 */
	private String dealTradeResultOfNutsNet(SLSHttpInterfaceInfo info,
			String originalGoodsId, String orderId, Head head,
			String orderTime, String paymentOrderNo) {
		NutsNetTradeResInfo tradeResInfo = null;
		tradeResInfo = tradeOfNutsNet(info, originalGoodsId, orderId, head,
				orderTime);

		// 返回给上层对象
		SLSHttpInterfaceInfo sLSHttpInterfaceInfo = new SLSHttpInterfaceInfo();
		// 订单结果
		String status = tradeResInfo.getStatus();
		if ("ORDER_SUCCESS".equalsIgnoreCase(status)) { // 充值成功
			sLSHttpInterfaceInfo.setResMsg("SUCCESS");
			sLSHttpInterfaceInfo.setPtOrderNo(info.getPtOrderNo());
			sLSHttpInterfaceInfo.setStatus("ORDER_SUCCESS");
			sLSHttpInterfaceInfo.setSupOrderNo(orderId);
			sLSHttpInterfaceInfo.setSupOrderSuccessTime(tradeResInfo
					.getSupOrderSuccessTime());
		} else if ("ORDER_FAILED".equalsIgnoreCase(status)
				|| "REQUEST_FAILED".equalsIgnoreCase(status)) { // 充值失败
			sLSHttpInterfaceInfo.setResMsg("FAILED");
			sLSHttpInterfaceInfo.setFailedCode("208");
			sLSHttpInterfaceInfo.setFailedReason("充值失败");
			sLSHttpInterfaceInfo.setPtOrderNo(info.getPtOrderNo());
			sLSHttpInterfaceInfo.setStatus("ORDER_FAILED");
			sLSHttpInterfaceInfo.setSupOrderNo(orderId);

			// 更新订单
			GoodsOrderInfo goodsOrderInfo1 = new GoodsOrderInfo();
			DeductionRefundInfo dedInfo = null;
			String paymentStatus = "";
			// 退款
			dedInfo = DeductionRefund.invokeDeductRefund(info, orderId, "1",
					orderTime, paymentOrderNo, head, goodsOrderDAO);
			if (dedInfo != null) {
				paymentStatus = dedInfo.getPaymentStatus();
			}
			if ("1".equals(paymentStatus)) { // 成功
				goodsOrderInfo1.setIsPay("3"); // 退款成功

				// 退款成功，通知下游用户
				DeductionRefund.noticeUserRefundMsg(orderId, dedInfo,
						goodsOrderDAO, downstreamUserDAO, goodsOrderLogDAO);

			} else if ("2".equals(paymentStatus)) {
				goodsOrderInfo1.setIsPay("2"); // 退款失败
			}
			try {
				updateGoodsOrder(orderId, head, goodsOrderInfo1);
			} catch (Exception e) {
				log.error(e);
				throw new ServerDisponseException(
						ExceptionCodeDes.ACCESS_DATABASE_ERROR.getCode(),
						ExceptionCodeDes.ACCESS_DATABASE_ERROR.getDescription());
			}

			// ...调用退款主动通知接口（有待于后期完善）
		} else if ("ORDER_UNDERWAY".equalsIgnoreCase(status)) { // 订单处理中
			sLSHttpInterfaceInfo.setResMsg("SUCCESS");
			sLSHttpInterfaceInfo.setFailedCode("209");
			sLSHttpInterfaceInfo.setFailedReason("订单正在处理中");
			sLSHttpInterfaceInfo.setPtOrderNo(info.getPtOrderNo());
			sLSHttpInterfaceInfo.setStatus("ORDER_UNDERWAY");
			sLSHttpInterfaceInfo.setSupOrderNo(orderId);
		} else if ("ORDER_NOT_EXIST".equalsIgnoreCase(status)) { // 订单不存在
			sLSHttpInterfaceInfo.setResMsg("SUCCESS");
			sLSHttpInterfaceInfo.setFailedCode("210");
			sLSHttpInterfaceInfo.setFailedReason("订单存疑");
			sLSHttpInterfaceInfo.setPtOrderNo(info.getPtOrderNo());
			sLSHttpInterfaceInfo.setStatus("ORDER_DUBIOUS");
			sLSHttpInterfaceInfo.setSupOrderNo(orderId);
		}

		sLSHttpInterfaceInfo.setGameAccount(info.getGameAccount());
		sLSHttpInterfaceInfo.setUnitPrice(info.getUnitPrice());
		sLSHttpInterfaceInfo.setBuyNum(info.getBuyNum());

		String totalPrice = info.getTotalPrice();
		String chargeTypeName = info.getChargeTypeName();
		if (chargeTypeName != null && !("".equals(chargeTypeName))) {
			totalPrice = DeductionRefund.calculateTotalPrice(info,
					chargeTypeName, originalGoodsId, chargeTypeInfoDAO);
		}
		sLSHttpInterfaceInfo.setTotalPrice(totalPrice);
		String resultBody = null;
		resultBody = gson.toJson(sLSHttpInterfaceInfo);
		return resultBody;
	}

	/**
	 * 殴飞充值返回结果处理
	 * 
	 * @param info
	 * @param originalGoodsId
	 * @param orderId
	 * @param head
	 * @return
	 */
	private String dealTradeResultOfOhFei(SLSHttpInterfaceInfo info,
			String originalGoodsId, String orderId, Head head,
			String orderTime, String paymentOrderNo) {
		OhFeiTradeInfo resInfo = null;
		// 调用交易方法
		resInfo = tradeOfOhFei(info, originalGoodsId, orderId, head, orderTime);
		// 返回给上层对象
		SLSHttpInterfaceInfo sLSHttpInterfaceInfo = new SLSHttpInterfaceInfo();
		String status = "2"; // 处理中
		String result = null;
		// 退款操作
		DeductionRefundInfo dedInfo = null;

		// 如果成功将为1，澈消(充值失败)为9，充值中为0,
		// 只能当状态为9时，商户才可以退款给用户。
		if (resInfo != null) {
			String retcode = resInfo.getRetcode();
			if ("1".equals(retcode)) {
				String game_state = resInfo.getGame_state();
				if ("1".equals(game_state)) { // 成功
					status = "1";
					result = "ORDER_SUCCESS";
					sLSHttpInterfaceInfo.setResMsg("SUCCESS");
					sLSHttpInterfaceInfo.setPtOrderNo(info.getPtOrderNo());
					sLSHttpInterfaceInfo.setStatus("ORDER_SUCCESS");
					sLSHttpInterfaceInfo.setSupOrderNo(orderId);
					String now = ServerDateAndTime.getNowDateTime();
					sLSHttpInterfaceInfo.setSupOrderSuccessTime(now);
				} else if ("0".equals(game_state)) { // 处理中
					status = "2";
					sLSHttpInterfaceInfo.setResMsg("SUCCESS");
					sLSHttpInterfaceInfo.setPtOrderNo(info.getPtOrderNo());
					sLSHttpInterfaceInfo.setStatus("ORDER_UNDERWAY");
					sLSHttpInterfaceInfo.setSupOrderNo(orderId);
				} else if ("9".equals(game_state)) { // 失败
					status = "0";
					result = "ORDER_FAILED";
					sLSHttpInterfaceInfo.setResMsg("FAILED");
					sLSHttpInterfaceInfo.setFailedCode("208");
					sLSHttpInterfaceInfo.setFailedReason("充值失败");
					sLSHttpInterfaceInfo.setPtOrderNo(info.getPtOrderNo());
					sLSHttpInterfaceInfo.setStatus("ORDER_FAILED");
					sLSHttpInterfaceInfo.setSupOrderNo(orderId);

					// 给用户退款
					dedInfo = DeductionRefund
							.invokeDeductRefund(info, orderId, "1", orderTime,
									paymentOrderNo, head, goodsOrderDAO);
				}
			} else { // 欧非上游下单不成功
				status = "0";
				result = "ORDER_FAILED";
				sLSHttpInterfaceInfo.setResMsg("FAILED");
				sLSHttpInterfaceInfo.setFailedCode("208");
				sLSHttpInterfaceInfo.setFailedReason("充值失败");
				sLSHttpInterfaceInfo.setPtOrderNo(info.getPtOrderNo());
				sLSHttpInterfaceInfo.setStatus("ORDER_FAILED");
				sLSHttpInterfaceInfo.setSupOrderNo(orderId);
				// 给用户退款
				dedInfo = DeductionRefund.invokeDeductRefund(info, orderId,
						"1", orderTime, paymentOrderNo, head, goodsOrderDAO);
			}
		}
		sLSHttpInterfaceInfo.setGameAccount(info.getGameAccount());
		sLSHttpInterfaceInfo.setUnitPrice(info.getUnitPrice());
		sLSHttpInterfaceInfo.setBuyNum(info.getBuyNum());

		String totalPrice = info.getTotalPrice();
		String chargeTypeName = info.getChargeTypeName();
		if (chargeTypeName != null && !("".equals(chargeTypeName))) {
			totalPrice = DeductionRefund.calculateTotalPrice(info,
					chargeTypeName, originalGoodsId, chargeTypeInfoDAO);
		}
		sLSHttpInterfaceInfo.setTotalPrice(totalPrice);
		String resultBody = null;
		resultBody = gson.toJson(sLSHttpInterfaceInfo);

		/**
		 * 更新订单
		 * 
		 */
		GoodsOrderInfo goodsOrderInfo = new GoodsOrderInfo();
		goodsOrderInfo.setStatus(status);
		goodsOrderInfo.setResult(result);

		String paymentStatus = "";
		if (dedInfo != null) {
			paymentStatus = dedInfo.getPaymentStatus();
		}
		if ("1".equals(paymentStatus)) { // 退款成功
			goodsOrderInfo.setIsPay("3"); // 退款成功
		} else if ("2".equals(paymentStatus)) { // 退款失败
			goodsOrderInfo.setIsPay("2"); // 退款失败
		}

		try {
			// 根据交易返回的结果更新订单表
			updateGoodsOrder(orderId, head, goodsOrderInfo);
		} catch (Exception e) {
			log.error(e);
			throw new ServerDisponseException(
					ExceptionCodeDes.ACCESS_DATABASE_ERROR.getCode(),
					ExceptionCodeDes.ACCESS_DATABASE_ERROR.getDescription());
		}

		return resultBody;
	}

	/**
	 * 坚果网络交易请求
	 * 
	 * @param info
	 * @param originalGoodsId
	 * @param orderId
	 * @param head
	 * @param orderTime
	 * @return
	 */
	private NutsNetTradeResInfo tradeOfNutsNet(SLSHttpInterfaceInfo info,
			String originalGoodsId, String orderId, Head head, String orderTime) {
		NutsNetTradeResInfo tradeResInfo = null;
		// 从配置文件中获取密钥
		NutsNetServerInfo serverInfo = NutsNetAssembleHttpUrl.getKeyValue();
		// 购买数量
		String buyNum = info.getBuyNum();
		// 商品单价
		String unitPrice = "";
		// 商品总价
		String sum = "";
		// 坚果网络商品名称全称
		String name = "";
		// 游戏公司名称
		String company = "";

		NutsNetGoodsInfo nutsNetGoodsInfo = null;
		nutsNetGoodsInfo = nutsNetGoodsInfoDAO.queryById(originalGoodsId);
		if (nutsNetGoodsInfo != null) {
			unitPrice = nutsNetGoodsInfo.getUnitPrice();
			name = nutsNetGoodsInfo.getName();
			if (name != null && !("".equals(name))) {
				String[] nameArr = name.split("-");
				company = nameArr[0];
			}
		}

		double value = Double.parseDouble(unitPrice);
		String priceStr = value * 1000 + "";
		String unitPriceStr = DataConversion.converData(priceStr);

		int unitPriceValue = Integer.parseInt(unitPriceStr);
		int buyNumValue = Integer.parseInt(buyNum);
		long sumPriceValue = 0;
		sumPriceValue = unitPriceValue * buyNumValue;
		String sumStr = sumPriceValue + "";
		sum = DataConversion.converIntegerToString(sumStr);

		String accountTypeName = info.getAccountTypeName();
		// 充值账户类型Id
		String hidAccountType = "";
		AccountTypeInfo accountTypeInfo = new AccountTypeInfo();
		accountTypeInfo.setGoodsId(originalGoodsId);
		accountTypeInfo.setAccountTypeName(accountTypeName);
		hidAccountType = accountTypeDAO.queryAccountType(accountTypeInfo);

		String chargeTypeName = info.getChargeTypeName();
		// 充值方式或计费类型Id
		String hidChargeType = "";
		ChargeTypeInfo chargeTypeInfo = new ChargeTypeInfo();
		chargeTypeInfo.setGoodsId(originalGoodsId);
		chargeTypeInfo.setChargetypeName(chargeTypeName);
		hidChargeType = chargeTypeInfoDAO.queryChargeType(chargeTypeInfo);

		String gameAreaName = info.getGameArea();
		// 充值区域Id
		String hidGameArea = "";
		NutsNetGoodsAreaInfo nutsNetGoodsAreaInfo = new NutsNetGoodsAreaInfo();
		nutsNetGoodsAreaInfo.setGoodsId(originalGoodsId);
		nutsNetGoodsAreaInfo.setChargetypeName(chargeTypeName);
		nutsNetGoodsAreaInfo.setGameAreaName(gameAreaName);
		List<NutsNetGoodsAreaInfo> nngaList = null;
		nngaList = nutsNetGoodsAreaDAO.queryGameArea(nutsNetGoodsAreaInfo);
		if (nngaList != null && nngaList.size() > 0) {
			NutsNetGoodsAreaInfo nngaInfo = nngaList.get(0);
			hidGameArea = nngaInfo.getGameAreaId();
		}

		String gift = "";
		// 赠品Id
		String hidGift = "";
		List<ChooseGemInfo> giftList = null;
		ChooseGemInfo chooseGemInfo = new ChooseGemInfo();
		chooseGemInfo.setGoodsId(originalGoodsId);
		chooseGemInfo.setChargeTypeName(chargeTypeName);
		giftList = chooseGemDAO.queryGift(chooseGemInfo);
		if (giftList != null && giftList.size() > 0) {
			ChooseGemInfo chooseGemInfo1 = giftList.get(0);
			if (chooseGemInfo1 != null) {
				gift = chooseGemInfo1.getChoosegemName();
				hidGift = chooseGemInfo1.getChoosegemId();
			}
		}

		String gamesrvName = info.getGameServer();
		// 充值服务器Id
		String hidGameSrv = "";
		NutsNetGoodsServerInfo gameServerInfo = new NutsNetGoodsServerInfo();
		gameServerInfo.setGoodsId(originalGoodsId);
		gameServerInfo.setGameAreaName(gameAreaName);
		gameServerInfo.setGamesrvName(gamesrvName);
		List<String> hidGameSrvs = nutsNetGoodsServerDAO
				.queryGameServer(gameServerInfo);
		if (hidGameSrvs != null && !hidGameSrvs.isEmpty()) {
			hidGameSrv = hidGameSrvs.get(0);
		}

		String chargeTypeNameVal = info.getChargeTypeName();
		if (chargeTypeNameVal != null && !("".equals(chargeTypeNameVal))) {
			sum = calculateTotalPriceOfSupply(info, chargeTypeNameVal,
					originalGoodsId, unitPrice, sum);
		}

		// 签名字符串
		String sign = createSignStr(info, serverInfo, orderId, originalGoodsId,
				orderTime, unitPrice, sum, hidAccountType, hidChargeType,
				hidGameArea, gift, hidGift, hidGameSrv, company);
		String paraStr = "";
		try {
			paraStr = assembleParameter(info, serverInfo, orderId, sign,
					originalGoodsId, orderTime, unitPrice, sum, hidAccountType,
					hidChargeType, hidGameArea, hidGameSrv, gift, hidGift,
					company);
		} catch (UnsupportedEncodingException e) {
			log.error(e);
			throw new ServerDisponseException(
					ExceptionCodeDes.TRANS_CODE_FAILURE.getCode(),
					ExceptionCodeDes.TRANS_CODE_FAILURE.getDescription());
		}
		// 坚果网络接口服务path
		String path = "OrderTrade.aspx";
		String tradeUrl = NutsNetAssembleHttpUrl.assembleHttpUrl(paraStr, path);
		log.info("坚果网络请求url：" + tradeUrl);
		// 发送http请求
		tradeResInfo = sendHttpRequest(tradeUrl, head);

		// 订单结果
		String orderResult = "";
		// 坚果网络平台订单号
		String supOrderNo = "";
		// SUP平台充值成功时间
		String supOrderSuccessTime = "";
		if (tradeResInfo != null) {
			orderResult = tradeResInfo.getStatus();
			supOrderNo = tradeResInfo.getSupOrderNo();
			supOrderSuccessTime = tradeResInfo.getSupOrderSuccessTime();
		}

		String status = "";
		// 0：失败 1：成功 2：处理中 3：存疑 4 ：冲销'
		if ("ORDER_SUCCESS".equals(orderResult)) {
			status = "1";
		} else if ("ORDER_FAILED".equals(orderResult)) {
			status = "0";
		} else if ("ORDER_UNDERWAY".equals(orderResult)) {
			status = "2";
		} else {
			status = "3";
		}

		GoodsOrderInfo goodsOrderInfo = new GoodsOrderInfo();
		goodsOrderInfo.setStatus(status);
		goodsOrderInfo.setSupOrderId(supOrderNo);
		goodsOrderInfo.setSupOrderSuccessTime(supOrderSuccessTime);
		goodsOrderInfo.setResult(orderResult);
		try {
			// 根据交易返回的结果更新订单表
			updateGoodsOrder(orderId, head, goodsOrderInfo);
		} catch (Exception e) {
			log.error(e);
			throw new ServerDisponseException(
					ExceptionCodeDes.ACCESS_DATABASE_ERROR.getCode(),
					ExceptionCodeDes.ACCESS_DATABASE_ERROR.getDescription());
		}

		return tradeResInfo;
	}

	/**
	 * 殴飞交易请求
	 * 
	 * @param info
	 * @param originalGoodsId
	 * @param orderId
	 * @param head
	 * @param orderTime
	 * @return
	 */
	private OhFeiTradeInfo tradeOfOhFei(SLSHttpInterfaceInfo info,
			String originalGoodsId, String orderId, Head head, String orderTime) {
		OhFeiTradeInfo resInfo = null;
		String paraStr = assembleParameterOfOhFeiTrade(info, originalGoodsId,
				orderId, orderTime);
		// 殴飞直充交易接口服务path
		String path = "onlineorder.do";
		String url = OhFeiAssembleHttpUrl.assembleHttpUrl(paraStr, path);
		// 发送http请求
		resInfo = sendHttpRequestOfOhFeiDirectTrade(url, head);
		// 订单结果
		String orderResult = "";
		// 平台订单号
		String supOrderNo = "";
		if (resInfo != null) {
			// 订单结果
			orderResult = resInfo.getGame_state();
			// 平台订单号
			supOrderNo = resInfo.getOrderid();
		}
		// SUP平台充值成功时间
		String supOrderSuccessTime = "";

		String status = "";
		if ("0".equals(orderResult)) { // 处理中
			status = "2";
		} else if ("1".equals(orderResult)) { // 充值成功
			status = "1";
		} else if ("9".equals(orderResult)) { // 充值失败
			status = "0";
		} else {
			status = "3"; // 充值存疑
		}
		GoodsOrderInfo goodsOrderInfo = new GoodsOrderInfo();
		goodsOrderInfo.setStatus(status);
		goodsOrderInfo.setSupOrderId(supOrderNo);
		goodsOrderInfo.setSupOrderSuccessTime(supOrderSuccessTime);
		goodsOrderInfo.setResult(orderResult);
		try {
			// 根据交易返回的结果更新订单表
			updateGoodsOrder(orderId, head, goodsOrderInfo);
		} catch (Exception e) {
			log.error("请求ID" + head.getRequestId() + "，根据殴飞返回的结果更新订单时出现异常！", e);
			throw new ServerDisponseException(
					ExceptionCodeDes.ACCESS_DATABASE_ERROR.getCode(),
					ExceptionCodeDes.ACCESS_DATABASE_ERROR.getDescription());
		}

		return resInfo;
	}

	/**
	 * 根据交易返回的结果更新订单表
	 * 
	 * @param orderId
	 * @param head
	 * @param info
	 */
	private void updateGoodsOrder(String orderId, Head head, GoodsOrderInfo info) {
		String status = "";
		String supOrderNo = "";
		String supOrderSuccessTime = "";
		String cardNoPwd = "";
		String cardId = "";
		String orderResult = "";
		String isPay = "";
		String payTime = "";
		String paymentOrderNo = "";
		if (info != null) {
			status = info.getStatus();
			supOrderNo = info.getSupOrderId();
			supOrderSuccessTime = info.getSupOrderSuccessTime();
			cardNoPwd = info.getCardNoPwd();
			cardId = info.getCardsInformation();
			orderResult = info.getResult();
			isPay = info.getIsPay();
			payTime = info.getPayTime();
			paymentOrderNo = info.getPaymentOrderNo();
		}

		GoodsOrderInfo goodsOrderInfo = new GoodsOrderInfo();
		GoodsOrderInfo goodsOrderInfo1 = new GoodsOrderInfo();

		goodsOrderInfo.setOrderId(orderId);
		goodsOrderInfo.setStatus(status);
		goodsOrderInfo.setSupOrderId(supOrderNo);
		goodsOrderInfo.setSupOrderSuccessTime(supOrderSuccessTime);
		goodsOrderInfo.setResult(orderResult);
		goodsOrderInfo.setIsPay(isPay);
		goodsOrderInfo.setPayTime(payTime);
		goodsOrderInfo.setPaymentOrderNo(paymentOrderNo);
		goodsOrderInfo.setCardsInformation(cardId);

		if (cardNoPwd != null && !("".equals(cardNoPwd))) { // 提取卡密时
			goodsOrderInfo.setCardNoPwd(cardNoPwd);
		}

		goodsOrderInfo.setSynOrAsy("0"); // 同步通知标识
		// 数据更新
		try {
			goodsOrderDAO.update(goodsOrderInfo);
		} catch (Exception e) {
			log.error(
					"updateGoodsOrder处理[" + head.getRequestId() + "]的请求出现异常！",
					e);
			throw new ServerDisponseException(
					ExceptionCodeDes.ACCESS_DATABASE_ERROR.getCode(),
					ExceptionCodeDes.ACCESS_DATABASE_ERROR.getDescription());
		}

		// 订单日志表插记录
		try {
			goodsOrderInfo1 = this.goodsOrderDAO.queryByOrderId(orderId);
			GoodsOrderLog orderLog = Helper.copy(goodsOrderInfo1);
			orderLog.setId(UUID.randomUUID().toString());
			orderLog.setModifyTime(ServerDateAndTime.getNowDateTimeOfFormat());
			this.goodsOrderLogDAO.insert(orderLog);
		} catch (Exception e) {
			log.error(e);
			throw new ServerDisponseException(
					ExceptionCodeDes.ACCESS_DATABASE_ERROR.getCode(),
					ExceptionCodeDes.ACCESS_DATABASE_ERROR.getDescription());
		}
	}

	/**
	 * 发送http请求，并对返回的xml格式的结果进行解析
	 * 
	 * @param url
	 * @return
	 */
	private NutsNetTradeResInfo sendHttpRequest(String url, Head head) {
		NutsNetTradeResInfo resInfo = null;
		HttpClient httpClient = new HttpClient();
		try {
			// 供应商返回消息编码方式
			String supplyEncode = "GBK";
			log.info("请求ID：" + head.getRequestId() + "，发送到坚果网络直充接口的请求参数：" + url);
			String xmlStr = httpClient.doGet(url, supplyEncode);
			log.info("请求ID：" + head.getRequestId() + "，坚果网络直充接口的返回结果：" + xmlStr);
			// 对返回的xml格式字符串数据进行解析
			List<NutsNetTradeResInfo> tradeResList = TradeResponseSaxParseXml
					.parseXmlString(xmlStr);
			if (tradeResList != null) {
				resInfo = tradeResList.get(0);

				if (resInfo != null) {
					log.info("请求ID：" + head.getRequestId()
							+ "，坚果网络交易返回消息内容    \n手拉手订单编号："
							+ resInfo.getPtOrderNo() + "\n订单结果:"
							+ resInfo.getStatus() + "\nSUP平台订单号:"
							+ resInfo.getSupOrderNo() + "\nSUP平台充值成功时间:"
							+ resInfo.getSupOrderSuccessTime() + "\n失败代码:"
							+ resInfo.getFailedCode() + "\n失败原因:"
							+ resInfo.getFailedReason());
				}
				return resInfo;
			}
		} catch (Exception e) {
			log.error("请求ID：" + head.getRequestId() + "，坚果网络直充交易请求异常！", e);
			throw new ServerDisponseException(
					ExceptionCodeDes.HTTP_URL_FAILED.getCode(),
					ExceptionCodeDes.HTTP_URL_FAILED.getDescription());
		}
		return resInfo;
	}

	/**
	 * http请求url所传参数字符串拼接
	 * 
	 * @param info
	 * @param serverInfo
	 * @param orderId
	 * @param sign
	 * @param originalGoodsId
	 * @param orderTime
	 * @param unitPrice
	 * @param sum
	 * @param hidAccountType
	 * @param hidChargeType
	 * @param hidGameArea
	 * @param hidGameSrv
	 * @param gift
	 * @param hidGift
	 * @return
	 * @throws UnsupportedEncodingException
	 */
	private String assembleParameter(SLSHttpInterfaceInfo info,
			NutsNetServerInfo serverInfo, String orderId, String sign,
			String originalGoodsId, String orderTime, String unitPrice,
			String sum, String hidAccountType, String hidChargeType,
			String hidGameArea, String hidGameSrv, String gift, String hidGift,
			String company) throws UnsupportedEncodingException {
		String buyNum = info.getBuyNum();
		String chargeTypeName = info.getChargeTypeName();
		if (chargeTypeName != null && !("".equals(chargeTypeName))) {
			boolean flag1 = ProcessString.isContainYuan(chargeTypeName);
			if (flag1) {
				boolean flag2 = ProcessString.isHasDigital(chargeTypeName);
				if (flag2) {
					buyNum = hidChargeType;
				}
			}
		}

		// 充值账户类型
		String accountType = info.getAccountTypeName();
		// 游戏账号
		String accountVal = info.getGameAccount();
		// 充值区域名称
		String gameArea = info.getGameArea();
		// 充值服务器名称
		String gameSrv = info.getGameServer();
		NutsNetGoodsDetailTop detailTop = null;
		detailTop = nutsNetGoodsDetailTopDAO.queryInfo(originalGoodsId);
		if (detailTop != null) {
			String gametype = detailTop.getGametype();
			if ("战网一卡通".equals(gametype)) {
				String username = detailTop.getUsername();
				accountVal = username;
				accountVal = URLEncoder.encode(accountVal, "GBK"); // GBK编码
				accountType = info.getGameAccount();
				hidAccountType = info.getGameAccount();
			}
			if ("CF点券".equals(gametype)) {
				gameArea = gameSrv;
				hidGameArea = hidGameSrv;
				gameSrv = null;
				hidGameSrv = null;
			}
		}

		log.info("坚果网络交易请求消息内容     \n合作平台编号:"
				+ serverInfo.getPartnerId().trim() + "\n合作方用户编号:"
				+ serverInfo.getSupUserId().trim() + "\n商品中心商品编号:"
				+ info.getGoodsId() + "\n手拉手订单编号:" + orderId + "\n合作方买家付款时间:"
				+ orderTime + "\n购买数量:" + buyNum + "\nSup供货价格单价:"
				+ info.getUnitPrice() + "\n总价 :" + sum + "\n充值账号:"
				+ info.getGameAccount() + "\n最终购买用户IP地址:"
				+ info.getMerchantIP() + "\n充值账户类型:" + accountType
				+ "\n充值方式类型:" + info.getChargeTypeName() + "\n充值区域名称:"
				+ info.getGameArea() + "\n充值服务器名称:" + info.getGameServer()
				+ "\n异步通知地址:" + info.getNotifyUrl());
		// 支付时间
		String ptPayTime = orderTime;

		StringBuffer strBuf = new StringBuffer();
		strBuf.append("partnerId=");
		String partnerId = serverInfo.getPartnerId();
		if (partnerId != null && !("".equals(partnerId))) {
			partnerId = partnerId.trim();
		}
		strBuf.append(partnerId);
		strBuf.append("&");
		strBuf.append("supUserId=");
		String supUserId = serverInfo.getSupUserId();
		if (supUserId != null && !("".equals(supUserId))) {
			supUserId = supUserId.trim();
		}
		strBuf.append(supUserId);
		strBuf.append("&");
		strBuf.append("supProductId=");
		strBuf.append(originalGoodsId);
		strBuf.append("&");
		strBuf.append("ptOrderNo=");
		strBuf.append(orderId);
		strBuf.append("&");
		strBuf.append("ptPayTime=");
		strBuf.append(ptPayTime);
		strBuf.append("&");
		strBuf.append("buyNum=");
		strBuf.append(buyNum);
		strBuf.append("&");
		strBuf.append("unitPrice=");
		strBuf.append(unitPrice);
		strBuf.append("&");
		strBuf.append("sum=");
		strBuf.append(sum);
		if(StringUtils.isBlank(accountVal)){
			strBuf.append("&");
			strBuf.append("accountVal=");
			accountVal = URLEncoder.encode(accountVal, "GBK");
			strBuf.append(accountVal);
		}
		strBuf.append("&");
		strBuf.append("buyerIp=");
		strBuf.append(info.getMerchantIP());

		if (!("".equals(accountType)) && accountType != null) {
			accountType = URLEncoder.encode(accountType, "GBK");
			strBuf.append("&");
			strBuf.append("accountType=");
			strBuf.append(accountType);
		}
		if (!("".equals(hidAccountType)) && hidAccountType != null) {
			hidAccountType = URLEncoder.encode(hidAccountType, "GBK");
			strBuf.append("&");
			strBuf.append("hidAccountType=");
			strBuf.append(hidAccountType);
		}

		// 充值方式或计费类型
		String chargeType = info.getChargeTypeName();
		if (!("".equals(chargeType)) && chargeType != null) {
			chargeType = URLEncoder.encode(chargeType, "GBK");
			strBuf.append("&");
			strBuf.append("chargeType=");
			strBuf.append(chargeType);
		}

		if ("九城".equals(company)) {
			hidChargeType = hidGift;
		}
		if (!("".equals(hidChargeType)) && hidChargeType != null) {
			hidChargeType = URLEncoder.encode(hidChargeType, "GBK");
			strBuf.append("&");
			strBuf.append("hidChargeType=");
			strBuf.append(hidChargeType);
		}

		if (!("".equals(gameArea)) && gameArea != null) {
			gameArea = URLEncoder.encode(gameArea, "GBK"); // GBK编码
			strBuf.append("&");
			strBuf.append("gameArea=");
			strBuf.append(gameArea);
		}
		if (!("".equals(hidGameArea)) && hidGameArea != null) {
			hidGameArea = URLEncoder.encode(hidGameArea, "GBK"); // GBK编码
			strBuf.append("&");
			strBuf.append("hidGameArea=");
			strBuf.append(hidGameArea);
		}

		if (!("".equals(gameSrv)) && gameSrv != null) {
			gameSrv = URLEncoder.encode(gameSrv, "GBK"); // GBK编码
			strBuf.append("&");
			strBuf.append("gameSrv=");
			strBuf.append(gameSrv);
		}
		if (!("".equals(hidGameSrv)) && hidGameSrv != null) {
			hidGameSrv = URLEncoder.encode(hidGameSrv, "GBK"); // GBK编码
			strBuf.append("&");
			strBuf.append("hidGameSrv=");
			strBuf.append(hidGameSrv);
		}

		// 赠品
		if (!("".equals(gift)) && gift != null) {
			gift = URLEncoder.encode(gift, "GBK"); // GBK编码
			strBuf.append("&");
			strBuf.append("gift=");
			strBuf.append(gift);
		}
		if (!("".equals(hidGift)) && hidGift != null) {
			hidGift = URLEncoder.encode(hidGift, "GBK"); // GBK编码
			strBuf.append("&");
			strBuf.append("hidGift=");
			strBuf.append(hidGift);
		}

		strBuf.append("&");
		strBuf.append("notifyUrl=");
		String notifyUrl = serverInfo.getNotifyUrl();
		if (notifyUrl != null && !("".equals(notifyUrl))) {
			notifyUrl = notifyUrl.trim();
		}
		strBuf.append(notifyUrl);
		strBuf.append("&");
		strBuf.append("sign=");
		strBuf.append(sign);
		String paraStr = strBuf.toString();

		return paraStr;
	}

	/**
	 * 生成签名字符串
	 * 
	 * @param info
	 * @param serverInfo
	 * @param orderId
	 * @param originalGoodsId
	 * @param orderTime
	 * @param unitPrice
	 * @param sum
	 * @param hidAccountType
	 * @param hidChargeType
	 * @param hidGameArea
	 * @param gift
	 * @param hidGift
	 * @param hidGameSrv
	 * @return
	 */
	private String createSignStr(SLSHttpInterfaceInfo info,
			NutsNetServerInfo serverInfo, String orderId,
			String originalGoodsId, String orderTime, String unitPrice,
			String sum, String hidAccountType, String hidChargeType,
			String hidGameArea, String gift, String hidGift, String hidGameSrv,
			String company) {
		String partnerKey = serverInfo.getPartnerKey(); // 为合作方商户密钥
		String supUserKey = serverInfo.getSupUserKey(); // 为合作方用户密钥
		String notifyUrl = serverInfo.getNotifyUrl(); // 回调地址
		if (partnerKey != null && !("".equals(partnerKey))) {
			partnerKey = partnerKey.trim();
		}
		if (supUserKey != null && !("".equals(supUserKey))) {
			supUserKey = supUserKey.trim();
		}
		if (notifyUrl != null && !("".equals(notifyUrl))) {
			notifyUrl = notifyUrl.trim();
		}

		// 充值账户类型名称
		String accountTypeName = info.getAccountTypeName();
		// 充值账号
		String accountVal = info.getGameAccount();
		// 充值区域名称
		String gameArea = info.getGameArea();
		// 充值服务器名称
		String gameSrv = info.getGameServer();
		NutsNetGoodsDetailTop detailTop = null;
		detailTop = nutsNetGoodsDetailTopDAO.queryInfo(originalGoodsId);
		if (detailTop != null) {
			String gametype = detailTop.getGametype();
			if ("战网一卡通".equals(gametype)) {
				String username = detailTop.getUsername();
				accountVal = username;
				accountTypeName = info.getGameAccount();
				hidAccountType = info.getGameAccount();
			}
			if ("CF点券".equals(gametype)) {
				gameArea = gameSrv;
				hidGameArea = hidGameSrv;
				gameSrv = null;
				hidGameSrv = null;
			}
		}

		// 最终购买用户IP地址
		String buyerIp = info.getMerchantIP();
		// 购买数量
		String buyNum = info.getBuyNum();
		String chargeTypeNameStr = info.getChargeTypeName();
		if (chargeTypeNameStr != null && !("".equals(chargeTypeNameStr))) {
			boolean flag1 = ProcessString.isContainYuan(chargeTypeNameStr);
			if (flag1) {
				boolean flag2 = ProcessString.isHasDigital(chargeTypeNameStr);
				if (flag2) {
					buyNum = hidChargeType;
				}
			}
		}

		// 充值方式或计费类型
		String chargeTypeName = info.getChargeTypeName();

		// 合作平台编号
		String partnerId = serverInfo.getPartnerId();
		if (partnerId != null) {
			partnerId = partnerId.trim();
		}
		// 合作方平台订单编号
		String ptOrderNo = orderId;
		// 合作方买家付款时间
		String ptPayTime = orderTime;
		// 商品中心商品编号
		String supProductId = originalGoodsId;
		// 合作方用户编号
		String supUserId = serverInfo.getSupUserId();
		if (supUserId != null) {
			supUserId = supUserId.trim();
		}

		StringBuilder strBu = new StringBuilder();
		if (!("".equals(accountTypeName)) && accountTypeName != null) {
			strBu.append("accountType");
			strBu.append(accountTypeName);
		}

		strBu.append("accountVal");
		strBu.append(accountVal);
		strBu.append("buyNum");
		strBu.append(buyNum);
		strBu.append("buyerIp");
		strBu.append(buyerIp);

		if (!("".equals(chargeTypeName)) && chargeTypeName != null) {
			strBu.append("chargeType");
			strBu.append(chargeTypeName);
		}
		if (!("".equals(gameArea)) && gameArea != null) {
			strBu.append("gameArea");
			strBu.append(gameArea);
		}
		if (!("".equals(gameSrv)) && gameSrv != null) {
			strBu.append("gameSrv");
			strBu.append(gameSrv);
		}
		if (!("".equals(gift)) && gift != null) {
			strBu.append("gift");
			strBu.append(gift);
		}
		if (!("".equals(hidAccountType)) && hidAccountType != null) {
			strBu.append("hidAccountType");
			strBu.append(hidAccountType);
		}

		if (!("".equals(hidChargeType)) && hidChargeType != null) {
			strBu.append("hidChargeType");
			if ("九城".equals(company)) {
				strBu.append(hidGift);
			} else {
				strBu.append(hidChargeType);
			}
		}
		if (!("".equals(hidGameArea)) && hidGameArea != null) {
			strBu.append("hidGameArea");
			strBu.append(hidGameArea);
		}
		if (!("".equals(hidGameSrv)) && hidGameSrv != null) {
			strBu.append("hidGameSrv");
			strBu.append(hidGameSrv);
		}
		if (!("".equals(hidGift)) && hidGift != null) {
			strBu.append("hidGift");
			strBu.append(hidGift);
		}

		strBu.append("notifyUrl");
		strBu.append(notifyUrl);
		strBu.append("partnerId");
		strBu.append(partnerId);
		strBu.append("ptOrderNo");
		strBu.append(ptOrderNo);

		strBu.append("ptPayTime");
		strBu.append(ptPayTime);
		strBu.append("sum");
		strBu.append(sum);
		strBu.append("supProductId");
		strBu.append(supProductId);
		strBu.append("supUserId");
		strBu.append(supUserId);
		strBu.append("unitPrice");
		strBu.append(unitPrice);
		strBu.append(partnerKey);
		strBu.append(supUserKey);

		String data = strBu.toString();
		System.out.println(data);
		String signStr = UtilMD5Encryption.createMD5EncryptionOfGBK(data);

		return signStr;
	}

	/**
	 * 判断能否进行交易
	 * 
	 * @param info
	 * @param head
	 * @param goodsSupplyManageInfo
	 * @return
	 */
	protected boolean judgmentCanTrading(SLSHttpInterfaceInfo info, Head head,
			GoodsSupplyManageInfo goodsSupplyManageInfo) {
		boolean flag = false;
		// 商品Id
		String goodsId = info.getGoodsId();
		// 售价（商品卖给下游用户的价格）
		String salePrice = "";
		// 价格模版
		String templateCode = "";
		// 下游传过来的单价
		String unitPrice = info.getUnitPrice();
		// 下游所传总价
		String totalPrice = info.getTotalPrice();
		// 购买数量
		String buyNum = info.getBuyNum();

		/**
		 * 检查该用户是否使用了价格模板
		 */
		String userNo = info.getUserNo();
		DownstreamUserInfo downstreamUserInfo = null;
		downstreamUserInfo = downstreamUserDAO.queryUserByUserNO(userNo);
		if (downstreamUserInfo != null) {
			templateCode = downstreamUserInfo.getTemplateCode();
		}

		if ("".equals(templateCode) || templateCode == null) { // 没有使用价格模版
			// 从商品信息表中，查询该商品的默认售价
			salePrice = queryGoodsSalePrice(goodsId, head);
		} else {
			// 根据商品编号和价格模版编号，查询特殊价格体系表中，该商品的价格
			SpecialPriceSystemInfo specialInfo = null;
			SpecialPriceSystemInfo specialInfo1 = new SpecialPriceSystemInfo();
			specialInfo1.setGoodsId(goodsId);
			specialInfo1.setTemplateCode(templateCode);
			specialInfo = specialPriceSystemDAO.queryOneRecord(specialInfo1);
			if (specialInfo != null) {
				salePrice = specialInfo.getInPrice() + ""; // 单位已经为厘
			}
		}

		int salePriceValue = 0;
		if (salePrice != null && !("".equals(salePrice))) {
			salePriceValue = Integer.parseInt(salePrice);
		}

		int unitPriceValue = DataConversion.converStringToInteger(unitPrice);
		int totalPriceValue = DataConversion.converStringToInteger(totalPrice);
		int buyNumValue = Integer.parseInt(buyNum);
		int totalPriceSls = salePriceValue * buyNumValue;
		// 商品进价
		int inPrice = goodsSupplyManageInfo.getGoodsCostPrice();
		int totalCostPrice = inPrice * buyNumValue;

		// 下游所传单价大于等于售价,订单总价要大于等于成本总价
		if ((unitPriceValue >= salePriceValue)
				&& (totalPriceValue >= totalPriceSls)
				&& (totalPriceValue >= totalCostPrice)) {
			flag = true;
		}

		return flag;
	}

	/**
	 * 向订单表插入数据
	 * 
	 * @param info
	 * @param goodsSupplyManageInfo
	 * @param head
	 * @param orderId
	 * @param merchantIP2
	 */
	protected void insertIntoGoodsOrder(SLSHttpInterfaceInfo info,
			GoodsSupplyManageInfo goodsSupplyManageInfo, Head head,
			String orderId, String orderTime, String merchantIP) {
		GoodsOrderInfo goodsOrderInfo = new GoodsOrderInfo();
		// 手拉手订单号
		goodsOrderInfo.setOrderId(orderId);
		// 商品编号
		goodsOrderInfo.setGoodsId(info.getGoodsId());
		// 商品名称
		goodsOrderInfo.setGoodsName(goodsSupplyManageInfo.getGoodsName());
		// 购买数量
		if (StringUtils.isNotEmpty(info.getBuyNum())) {
			goodsOrderInfo.setBuyNum(Integer.parseInt(info.getBuyNum()));
		}
		// 手拉手商品品牌编号
		goodsOrderInfo.setBrandId(goodsSupplyManageInfo.getGoodsCategoryId());
		// 商品品牌名称
		goodsOrderInfo.setBrandName(goodsSupplyManageInfo.getBrandName());
		// 玩家游戏账号
		goodsOrderInfo.setGameAccount(info.getGameAccount());
		// 手拉手订单生成时间
		goodsOrderInfo.setCreateOrderTime(orderTime);

		// 下游商户订单号
		goodsOrderInfo.setMerchantOrderId(info.getPtOrderNo());
		// 下游承包商编号(下游用户账号)
		goodsOrderInfo.setContractId(info.getUserNo());

		// 供应商编号
		goodsOrderInfo.setSupplyId(goodsSupplyManageInfo.getSuppliersId());
		// 供应商名称
		goodsOrderInfo.setSupplyName(goodsSupplyManageInfo.getSupplyName());
		// 商品面值
		goodsOrderInfo.setGoodsValue(goodsSupplyManageInfo.getGoodsValue());
		// 商品进价
		goodsOrderInfo.setGoodsCostPrice(goodsSupplyManageInfo
				.getGoodsCostPrice());

		// 商品售价
		String unitPriceVal = getGoodsSalePrice(info, head); // 单位已经为厘
		int unitPrice = Integer.parseInt(unitPriceVal);
		goodsOrderInfo.setGoodsSalePrice(unitPrice);

		// 总金额
		String totalPriceVal = "";
		int totalPrice = 0;
		// 购买数量
		String buyNum = info.getBuyNum();
		if (StringUtils.isNotEmpty(buyNum)) {
			int buyNumVal = Integer.parseInt(buyNum);
			totalPrice = buyNumVal * unitPrice;
		}
		String chargeTypeName = info.getChargeTypeName();
		if (chargeTypeName != null && !("".equals(chargeTypeName))) {
			String originalGoodsId = goodsSupplyManageInfo.getOriginalGoodsId();
			totalPriceVal = DeductionRefund.calculateTotalPrice(info,
					chargeTypeName, originalGoodsId, chargeTypeInfoDAO);
			totalPrice = DataConversion.converStringToInteger(totalPriceVal);
		}

		if (StringUtils.isNotEmpty(info.getTotalPrice())) {
			goodsOrderInfo.setTotalPrice(totalPrice);
		}
		// 区服
		String areaServer = info.getGameArea() + "##" + info.getGameServer();
		goodsOrderInfo.setAreaServer(areaServer);

		// 订单状态 (0：失败 1：成功 2：处理中 3：存疑 4 ：冲销)
		goodsOrderInfo.setStatus("2");

		// 1.卡密类型 2.直充类型
		// 计算佣金(对下游商品批发，不需要计算佣金)

		goodsOrderInfo.setMerchantIP(merchantIP);

		// 手拉手平台IP
		String slsIP = "";
		try {
			InetAddress addr = InetAddress.getLocalHost();
			slsIP = addr.getHostAddress();// 获得本机IP
		} catch (UnknownHostException e) {
			log.error(e);
			throw new ServerDisponseException(
					ExceptionCodeDes.OBTAIN_IP_FAILURE.getCode(),
					ExceptionCodeDes.OBTAIN_IP_FAILURE.getDescription());
		}
		goodsOrderInfo.setSlsPlatformIP(slsIP);

		// 订单是否删除 0 删除 1 没有删除
		goodsOrderInfo.setIsDelete("1");
		// 回调地址
		String notifyUrl = "";
		notifyUrl = info.getNotifyUrl();
		goodsOrderInfo.setNotifyUrl(notifyUrl);
		goodsOrderInfo.setUserhandleResult("unknown"); // 先赋默认值"未知"

		try {
			goodsOrderDAO.insert(goodsOrderInfo);
		} catch (Exception e) {
			log.error("Service处理[" + head.getRequestId() + "]的请求出现异常！", e);
			throw new ServerDisponseException(
					ExceptionCodeDes.ACCESS_DATABASE_ERROR.getCode(),
					ExceptionCodeDes.ACCESS_DATABASE_ERROR.getDescription());
		}

	}

	/**
	 * 获取商品单价
	 * 
	 * @param info
	 * @param head
	 * @return
	 * @date 2013-02-27
	 */
	private String getGoodsSalePrice(SLSHttpInterfaceInfo info, Head head) {
		// 商品Id
		String goodsId = info.getGoodsId();
		// 售价（商品卖给下游用户的价格）
		String salePrice = "";
		// 价格模版
		String templateCode = "";
		/**
		 * 检查该用户是否使用了价格模板
		 */
		String userNo = info.getUserNo();
		DownstreamUserInfo downstreamUserInfo = null;
		downstreamUserInfo = downstreamUserDAO.queryUserByUserNO(userNo);
		if (downstreamUserInfo != null) {
			templateCode = downstreamUserInfo.getTemplateCode();
		}

		if ("".equals(templateCode) || templateCode == null) { // 没有使用价格模版
			// 从商品信息表中，查询该商品的默认售价
			salePrice = queryGoodsSalePrice(goodsId, head);
		} else {
			// 根据商品编号和价格模版编号，查询特殊价格体系表中，该商品的价格
			SpecialPriceSystemInfo specialInfo = null;
			SpecialPriceSystemInfo specialInfo1 = new SpecialPriceSystemInfo();
			specialInfo1.setGoodsId(goodsId);
			specialInfo1.setTemplateCode(templateCode);
			specialInfo = specialPriceSystemDAO.queryOneRecord(specialInfo1);
			if (specialInfo != null) {
				salePrice = specialInfo.getInPrice() + ""; // 单位已经为厘
			}
		}

		return salePrice;
	}

	/**
	 * 单笔订单查询
	 * 
	 * @param body
	 * @param head
	 * @return
	 * @throws ServerDisponseException
	 */
	@Override
	public String querySinglePenOfTrade(String body, Head head)
			throws ServerDisponseException {
		if (log.isInfoEnabled()) {
			log.info("进入SLSHttpInterfaceService开始处理[" + head.getRequestId()
					+ "]的请求");
		}
		SLSHttpInterfaceInfo info = gson.fromJson(body,
				SLSHttpInterfaceInfo.class);
		if (info == null) {
			throw new ServerDisponseException(
					ExceptionCodeDes.PARSE_REQUEST_ERROR.getCode(),
					ExceptionCodeDes.PARSE_REQUEST_ERROR.getDescription());
		}

		// ***** 下游用户身份校验 *****
		String userNo = info.getUserNo();
		String userIP = info.getClientIp();
		String result = checkIdentity(userNo, userIP, false);
		if ("104".equals(result)) {
			// 返回给上层对象
			SLSHttpInterfaceInfo sLSHttpInterfaceInfo = new SLSHttpInterfaceInfo();
			sLSHttpInterfaceInfo.setResMsg("FAILED");
			sLSHttpInterfaceInfo.setFailedCode("104");
			sLSHttpInterfaceInfo.setFailedReason("合作方用户不存在");
			String resultBody = null;
			resultBody = gson.toJson(sLSHttpInterfaceInfo);
			return resultBody;
		} else { // 身份校验通过
			// 商户订单号
			String merchantOrderId = info.getPtOrderNo();
			String resultBody = null;
			// 返回给上层对象
			SLSHttpInterfaceInfo sLSHttpInterfaceInfo = new SLSHttpInterfaceInfo();

			try {
				GoodsOrderInfo goodsOrderInfo = new GoodsOrderInfo();
				goodsOrderInfo.setMerchantOrderId(merchantOrderId);
				goodsOrderInfo.setContractId(userNo);

				GoodsOrderInfo goodsOrderInfo1 = null;
				goodsOrderInfo1 = goodsOrderDAO
						.queryByMerchantOrderId(goodsOrderInfo);
				if (goodsOrderInfo1 != null) {
					String status = goodsOrderInfo1.getStatus();
					int value = Integer.parseInt(status);
					switch (value) {
					case 0:
						sLSHttpInterfaceInfo.setResMsg("FAILED");
						sLSHttpInterfaceInfo.setFailedCode("208");
						sLSHttpInterfaceInfo.setFailedReason("充值失败");
						sLSHttpInterfaceInfo.setPtOrderNo(goodsOrderInfo1
								.getMerchantOrderId());
						sLSHttpInterfaceInfo.setSupOrderNo(goodsOrderInfo1
								.getOrderId());
						sLSHttpInterfaceInfo.setStatus("ORDER_FAILED");
						break;
					case 1:
						sLSHttpInterfaceInfo.setResMsg("SUCCESS");
						sLSHttpInterfaceInfo.setPtOrderNo(goodsOrderInfo1
								.getMerchantOrderId());
						sLSHttpInterfaceInfo.setSupOrderNo(goodsOrderInfo1
								.getOrderId());
						sLSHttpInterfaceInfo.setStatus("ORDER_SUCCESS");
						break;
					case 2:
						sLSHttpInterfaceInfo.setResMsg("SUCCESS");
						sLSHttpInterfaceInfo.setFailedCode("209");
						sLSHttpInterfaceInfo.setFailedReason("订单正在处理中");
						sLSHttpInterfaceInfo.setPtOrderNo(goodsOrderInfo1
								.getMerchantOrderId());
						sLSHttpInterfaceInfo.setSupOrderNo(goodsOrderInfo1
								.getOrderId());
						sLSHttpInterfaceInfo.setStatus("ORDER_UNDERWAY");
						break;
					// ...

					default:
						break;
					}

				} else { // 订单不存在
					sLSHttpInterfaceInfo.setResMsg("FAILED");
					sLSHttpInterfaceInfo.setFailedCode("501");
					sLSHttpInterfaceInfo.setFailedReason("订单不存在");
				}

				resultBody = gson.toJson(sLSHttpInterfaceInfo);
			} catch (Exception e) {
				log.error("Service处理[" + head.getRequestId() + "]的请求出现异常！", e);
				throw new ServerDisponseException(
						ExceptionCodeDes.ACCESS_DATABASE_ERROR.getCode(),
						ExceptionCodeDes.ACCESS_DATABASE_ERROR.getDescription());
			}

			return resultBody;
		}
	}

	/**
	 * 提取卡密
	 * 
	 * @param body
	 * @param head
	 * @return
	 * @throws ServerDisponseException
	 */
	@Override
	public String insertOfPickingUpCard(String body, Head head)
			throws ServerDisponseException {
		if (log.isInfoEnabled()) {
			log.info("进入SLSHttpInterfaceService开始处理[" + head.getRequestId()
					+ "]的请求");
		}
		SLSHttpInterfaceInfo info = gson.fromJson(body,
				SLSHttpInterfaceInfo.class);
		boolean flag = checkDataOfPickingUpCard(info, head.getRequestId());
		if (flag) { // 数据校验通过

			// ***** 下游用户身份校验 *****
			String userNo = info.getUserNo();
			String userIP = info.getClientIp();
			String result = checkIdentity(userNo, userIP, false); // 绑定IP，第三个参数为true；不绑定IP，第三个参数为false
			if ("104".equals(result)) {
				// 返回给上层对象
				SLSHttpInterfaceInfo sLSHttpInterfaceInfo = new SLSHttpInterfaceInfo();
				sLSHttpInterfaceInfo.setResMsg("FAILED");
				sLSHttpInterfaceInfo.setFailedCode("104");
				sLSHttpInterfaceInfo.setFailedReason("合作方用户不存在");
				String resultBody = null;
				resultBody = gson.toJson(sLSHttpInterfaceInfo);
				return resultBody;
			} else if ("105".equals(result)) {
				SLSHttpInterfaceInfo sLSHttpInterfaceInfo = new SLSHttpInterfaceInfo();
				sLSHttpInterfaceInfo.setResMsg("FAILED");
				sLSHttpInterfaceInfo.setFailedCode("105");
				sLSHttpInterfaceInfo.setFailedReason("绑定的IP地址不匹配");
				String resultBody = null;
				resultBody = gson.toJson(sLSHttpInterfaceInfo);
				return resultBody;
			} else { // 身份校验通过
				// 商品Id
				String goodsId = info.getGoodsId();
				// ***** 获取手拉手订单编号 *****
				String orderId = null;
				orderId = getSlsOrderNo();
				// 最终购买用户IP地址【暂时模拟最终购买用户IP】
				String merchantIP = generateDycIp();

				List<GoodsSupplyManageInfo> supplyList = null;
				GoodsSupplyManageInfo goodsSupplyManageInfo = null;
				try {
					GoodsSupplyManageInfo goodsSupplyManageInfo1 = new GoodsSupplyManageInfo();
					goodsSupplyManageInfo1.setGoodsId(goodsId);
					goodsSupplyManageInfo1.setGoodsState("1"); // 上架
					// 查询供货价格最低的上游
					supplyList = goodsSupplyManageDAO
							.queryMininunPrice(goodsSupplyManageInfo1);
					if (supplyList != null && supplyList.size() > 0) {
						goodsSupplyManageInfo = supplyList.get(0);
					}
				} catch (Exception e) {
					log.error("Service处理[" + head.getRequestId() + "]的请求出现异常！",
							e);
					throw new ServerDisponseException(
							ExceptionCodeDes.ACCESS_DATABASE_ERROR.getCode(),
							ExceptionCodeDes.ACCESS_DATABASE_ERROR
									.getDescription());
				}
				// ***** 判断能否进行交易 *****
				boolean tradeFlag = judgmentCanTrading(info, head,
						goodsSupplyManageInfo);
				if (tradeFlag) { // 可以进行交易
					if (goodsSupplyManageInfo != null) {
						// 检查下游所传的订单总价是否正确
						boolean totalPriceFlag = checkTotalPrice(info,
								goodsSupplyManageInfo);
						if (totalPriceFlag) {
							// 写订单前，先判断该用户下订单是否重复提交
							GoodsOrderInfo goodsOrderInfo = new GoodsOrderInfo();
							goodsOrderInfo.setMerchantOrderId(info
									.getPtOrderNo());
							goodsOrderInfo.setContractId(info.getUserNo());
							String id = null;
							id = goodsOrderDAO
									.queryOrderIsExtisOfUserNo(goodsOrderInfo);
							if (id == null) { // 可以写订单
								// 订单时间戳
								String orderTime = ServerDateAndTime
										.getNowDateTimeOfFormat();
								// 向订单表写记录
								insertIntoGoodsOrder(info,
										goodsSupplyManageInfo, head, orderId,
										orderTime, merchantIP);

								// ************** 调用支付接口 ***************
								orderTime = orderTime.replace("-", "")
										.replace(":", "").replace(" ", "");
								String paymentStatus = ""; // 支付状态
								String paymentOrderNo = ""; // 支付交易单号
								DeductionRefundInfo deReFunInfo = null;
								deReFunInfo = DeductionRefund
										.invokeDeductRefund(info, orderId, "1",
												orderTime, paymentOrderNo,
												head, goodsOrderDAO);
								if (deReFunInfo != null) {
									paymentStatus = deReFunInfo
											.getPaymentStatus();
									paymentOrderNo = deReFunInfo.getTradeNo();
								}
								if ("1".equals(paymentStatus)) { // 支付成功
									String resultBody = null;
									// 是否提卡
									boolean isBuyCard = true;
									// 支付成功时的操作
									try {
										resultBody = operatePaySuccess(
												orderTime, paymentOrderNo,
												orderId, head,
												goodsSupplyManageInfo, info,
												isBuyCard, merchantIP);
									} catch (Exception e) {
										log.error("请求ID：" + head.getRequestId()
												+ "，调用上游接口出现异常！", e);
									}

									return resultBody;
								} else if ("2".equals(paymentStatus)) { // 支付失败
									String resultBody = null;
									// 支付失败时的操作
									try {
										resultBody = operatePayFailure(
												orderTime, paymentOrderNo,
												orderId, head, info);
									} catch (Exception e) {
										log.error("请求ID：" + head.getRequestId()
												+ "，支付失败时更新订单异常！", e);
									}
									return resultBody;
								} else if ("4".equals(paymentStatus)) { // 充销
									// ...
								}
							} else { // 订单重复提交
								String resultBody = null;
								resultBody = submitOrderRepeat();
								return resultBody;
							}
						} else { // 下游用户提交的订单金额不正确
							SLSHttpInterfaceInfo sLSHttpInterfaceInfo = new SLSHttpInterfaceInfo();
							sLSHttpInterfaceInfo.setResMsg("FAILED");
							sLSHttpInterfaceInfo.setFailedCode("504");
							sLSHttpInterfaceInfo.setFailedReason("该笔订单总金额不正确");
							String resultBody = null;
							resultBody = gson.toJson(sLSHttpInterfaceInfo);
							return resultBody;
						}
					} else { // 检查库存不足
						String resultBody = null;
						resultBody = checkReserveShortage();
						return resultBody;
					}
				} else {
					SLSHttpInterfaceInfo sLSHttpInterfaceInfo = new SLSHttpInterfaceInfo();
					sLSHttpInterfaceInfo.setResMsg("FAILED");
					sLSHttpInterfaceInfo.setFailedCode("503");
					sLSHttpInterfaceInfo.setFailedReason("售价低于进价");
					String resultBody = null;
					resultBody = gson.toJson(sLSHttpInterfaceInfo);
					return resultBody;
				}

			}
		}

		return null;
	}

	/**
	 * 殴飞提卡
	 * 
	 * @param info
	 * @param originalGoodsId
	 * @param orderId
	 * @param head
	 * @param paymentOrderNo
	 * @param orderTime
	 * @return
	 */
	private String obtainOhFeiCardGoods(SLSHttpInterfaceInfo info,
			String originalGoodsId, String orderId, Head head,
			String orderTime, String paymentOrderNo) {
		// 返回给上层对象
		SLSHttpInterfaceInfo sLSHttpInterfaceInfo = new SLSHttpInterfaceInfo();
		String paraStr = assembleParaOfOhFeiPickingUpCard(info,
				originalGoodsId, orderId);
		String path = "order.do";
		String url = OhFeiAssembleHttpUrl.assembleHttpUrl(paraStr, path);
		log.info("殴飞提卡url：" + url);
		List<OhFeiTradeInfo> resInfoList = sendHttpRequestOfOhFeiPickingUpCard(
				url, head);
		StringBuilder strBui = new StringBuilder();
		String cardid = null;
		String cardname = null;
		String cardnum = null;
		String cardIdPwd = null;
		// 上游订单号
		String orderid = null;

		if (resInfoList != null && resInfoList.size() > 0) {
			for (int i = 0; i < resInfoList.size(); i++) {
				OhFeiTradeInfo ohFeiTradeInfo = resInfoList.get(i);

				String cardno = ohFeiTradeInfo.getCardno();
				if (cardno != null && !("".equals(cardno))) {
					strBui.append(cardno); // 卡号
					strBui.append(",");
				}
				String cardpws = ohFeiTradeInfo.getCardpws();
				if (cardpws != null && !("".equals(cardpws))) {
					strBui.append(cardpws); // 卡密
					strBui.append(",");
				}
				String expiretime = ohFeiTradeInfo.getExpiretime();
				if (expiretime != null && !("".equals(expiretime))) {
					strBui.append(expiretime); // 有效期
				}
				strBui.append(";");

				cardid = ohFeiTradeInfo.getCardid();
				cardname = ohFeiTradeInfo.getCardname();
				cardnum = ohFeiTradeInfo.getCardnum();
				orderid = ohFeiTradeInfo.getOrderid();
			}

			String str = strBui.toString();
			if (str != null && !("".equals(str))) {
				cardIdPwd = str.substring(0, str.length() - 1);
			}

			GoodsOrderInfo goodsOrderInfo = new GoodsOrderInfo();
			goodsOrderInfo.setCardNoPwd(cardIdPwd);
			goodsOrderInfo.setCardsInformation(cardid);
			goodsOrderInfo.setSupOrderId(orderid);

			if (cardIdPwd != null && !("".equals(cardIdPwd))) {
				goodsOrderInfo.setStatus("1"); // 成功

				String time = ServerDateAndTime.getNowDateTime();
				goodsOrderInfo.setSupOrderSuccessTime(time);
			} else {
				goodsOrderInfo.setStatus("0"); // 失败

				// 更新订单
				DeductionRefundInfo dedInfo = null;
				String paymentStatus = "";
				// 退款
				dedInfo = DeductionRefund.invokeDeductRefund(info, orderId,
						"1", orderTime, paymentOrderNo, head, goodsOrderDAO);
				if (dedInfo != null) {
					paymentStatus = dedInfo.getPaymentStatus();
				}
				if ("1".equals(paymentStatus)) { // 成功
					goodsOrderInfo.setIsPay("3"); // 退款成功
					// 退款成功，通知下游用户
					DeductionRefund.noticeUserRefundMsg(orderId, dedInfo,
							goodsOrderDAO, downstreamUserDAO, goodsOrderLogDAO);
				} else if ("2".equals(paymentStatus)) {
					goodsOrderInfo.setIsPay("2"); // 退款失败
				}

			}
			try {
				updateGoodsOrder(orderId, head, goodsOrderInfo);
			} catch (Exception e) {
				log.error("请求ID：" + head.getRequestId()
						+ "根据殴飞提卡接口返回的结果更新订单时出现异常！", e);
				throw new ServerDisponseException(
						ExceptionCodeDes.ACCESS_DATABASE_ERROR.getCode(),
						ExceptionCodeDes.ACCESS_DATABASE_ERROR.getDescription());
			}
		}

		String resultBody = null;
		if (resInfoList != null) {
			sLSHttpInterfaceInfo.setResMsg("SUCCESS");
			sLSHttpInterfaceInfo.setCardid(cardid);
			sLSHttpInterfaceInfo.setCardname(cardname);
			sLSHttpInterfaceInfo.setCardnum(cardnum);
			sLSHttpInterfaceInfo.setCardNoPwdExptime(cardIdPwd);
			sLSHttpInterfaceInfo.setSupOrderNo(orderId);
			resultBody = gson.toJson(sLSHttpInterfaceInfo);
		}

		return resultBody;
	}

	/**
	 * 用户余额查询
	 * 
	 * @param body
	 * @param head
	 * @return
	 * @throws ServerDisponseException
	 */
	@Override
	public String queryUserBalance(String body, Head head)
			throws ServerDisponseException {
		if (log.isInfoEnabled()) {
			log.info("进入SLSHttpInterfaceService开始处理[" + head.getRequestId()
					+ "]的请求");
		}
		SLSHttpInterfaceInfo info = gson.fromJson(body,
				SLSHttpInterfaceInfo.class);
		boolean flag = checkDataOfUserBalance(info);
		if (flag) { // 数据校验通过
			// ***** 下游用户身份校验 *****
			String userNo = info.getUserNo();
			String userIP = info.getClientIp();
			String result = checkIdentity(userNo, userIP, false);
			if ("104".equals(result)) {
				// 返回给上层对象
				SLSHttpInterfaceInfo sLSHttpInterfaceInfo = new SLSHttpInterfaceInfo();
				sLSHttpInterfaceInfo.setResMsg("FAILED");
				sLSHttpInterfaceInfo.setFailedCode("104");
				sLSHttpInterfaceInfo.setFailedReason("合作方用户不存在");
				String resultBody = null;
				resultBody = gson.toJson(sLSHttpInterfaceInfo);
				return resultBody;
			} else { //
				String resultRes = sendHttpRequestOfBalance(info);
				SLSHttpInterfaceInfo balanceInfo = gson.fromJson(resultRes,
						SLSHttpInterfaceInfo.class);
				String balance = "";
				String balInfo = null;
				if (balanceInfo != null) {
					balance = balanceInfo.getBalance();
					balInfo = balanceInfo.getInfo();
				}
				// 返回给上层对象
				SLSHttpInterfaceInfo sLSHttpInterfaceInfo = new SLSHttpInterfaceInfo();
				if ((balInfo == null || "".equals(balInfo))
						&& (balance != null)) {
					sLSHttpInterfaceInfo.setResMsg("SUCCESS");
					sLSHttpInterfaceInfo.setFailedCode("");
					sLSHttpInterfaceInfo.setFailedReason("");
					sLSHttpInterfaceInfo.setBalance(balance);
				} else {
					sLSHttpInterfaceInfo.setResMsg("FAILED");
					sLSHttpInterfaceInfo.setFailedCode("210");
					sLSHttpInterfaceInfo.setFailedReason("余额查询失败");
				}
				String resultBody = null;
				resultBody = gson.toJson(sLSHttpInterfaceInfo);
				return resultBody;
			}
		}

		return null;
	}

	/**
	 * 发送余额查询http请求
	 */
	private String sendHttpRequestOfBalance(SLSHttpInterfaceInfo info) {
		String result = null;
		String url = assembleBalanceUrl(info);
		log.info(url);
		HttpClient httpClient = new HttpClient();
		// 供应商返回消息编码方式
		String supplyEncode = "UTF-8";
		try {
			result = httpClient.doGet(url, supplyEncode);
			log.info(result);
		} catch (Exception e) {
			log.error(e);
			throw new ServerDisponseException(
					ExceptionCodeDes.HTTP_URL_FAILED.getCode(),
					ExceptionCodeDes.HTTP_URL_FAILED.getDescription());
		}

		return result;
	}

	/**
	 * 余额查询请求url拼装
	 * 
	 * @param info
	 */
	private String assembleBalanceUrl(SLSHttpInterfaceInfo info) {
		// 请求地址
		String balanceAddress = null;
		// 余额查询密钥
		String balanceKey = null;
		// 用户编号
		String userNo = info.getUserNo();
		DeductionRefundInfo dedRefInfo = DeductionRefundResParse
				.readConfigurateFile();
		if (dedRefInfo != null) {
			balanceAddress = dedRefInfo.getBalanceAddress();
			balanceKey = dedRefInfo.getBalanceKey();
		}
		StringBuffer strBui = new StringBuffer();
		if (balanceAddress != null) {
			strBui.append(balanceAddress.trim());
		}
		strBui.append("?");
		strBui.append("trader.traderId=");
		strBui.append(userNo);
		String sign = createSignOfBanlance(userNo, balanceKey);
		strBui.append("&");
		strBui.append("key=");
		strBui.append(sign);

		String url = strBui.toString().trim();
		return url;
	}

	/**
	 * 余额查询请求参数签名字符串生成
	 * 
	 * @param
	 */
	private String createSignOfBanlance(String userNo, String balanceKey) {
		StringBuilder strBui = new StringBuilder();
		if (balanceKey != null) {
			strBui.append(userNo);
			strBui.append(balanceKey.trim());
		}
		String data = strBui.toString().trim();
		String result = UtilMD5Encryption.createMD5Encryption(data);

		return result;
	}

	/**
	 * 余额查询数据校验
	 * 
	 * @param info
	 * @return
	 */
	private boolean checkDataOfUserBalance(SLSHttpInterfaceInfo info) {
		boolean flag = false;
		String userNo = info.getUserNo();

		if ("".equals(userNo) || userNo == null) {
			throw new ServerDisponseException(
					ExceptionCodeDes.USER_ID_NULL.getCode(),
					ExceptionCodeDes.USER_ID_NULL.getDescription());
		} else {
			flag = true;
		}

		return flag;
	}

	/**
	 * 上游返回订单处理失败时，管理端退款
	 * 
	 * @param body
	 * @param head
	 * @return
	 * @throws ServerDisponseException
	 * @date 2012-11-20
	 */
	@Override
	public String updateRefundAboutOrder(String body, Head head)
			throws ServerDisponseException {
		if (log.isInfoEnabled()) {
			log.info("进入SLSHttpInterfaceService开始处理[" + head.getRequestId()
					+ "]的请求");
		}
		GoodsOrderInfo info = gson.fromJson(body, GoodsOrderInfo.class);
		if (info == null) {
			throw new ServerDisponseException(
					ExceptionCodeDes.PARSE_REQUEST_ERROR.getCode(),
					ExceptionCodeDes.PARSE_REQUEST_ERROR.getDescription());
		}

		boolean flag = checkDataOfRefund(info);
		if (flag) { // 检验通过
			DeductionRefundInfo deductionRefundInfo = new DeductionRefundInfo();
			// 用户编号
			deductionRefundInfo.setUserNo(info.getContractId());
			// 手拉手订单号
			deductionRefundInfo.setOrderNo(info.getOrderId());
			// 支付单号
			deductionRefundInfo.setTradeNo(info.getPaymentOrderNo());
			// 退款金额
			String totalPriceStr = info.getTotalPrice() + "";
			String totalPrice = DataConversion
					.converIntegerToString(totalPriceStr);
			deductionRefundInfo.setPaymentFee(totalPrice);
			// 支付类型
			deductionRefundInfo.setPaymentType("1"); // 支付类型(0 扣款,1 退款)
			// 下游用户IP地址
			deductionRefundInfo.setPaymentIP(info.getMerchantIP());

			String orderTime = ServerDateAndTime.getNowDateTime();
			deductionRefundInfo.setOrderTime(orderTime);

			DeductionRefundInfo deReFunInfo = null;
			String paymentStatus = null;
			String isPay = null;

			deReFunInfo = DeductionRefund.sendDeductionOrRefundMsg(
					deductionRefundInfo, head);
			if (deReFunInfo != null) {
				paymentStatus = deReFunInfo.getPaymentStatus();
			}
			if (paymentStatus != null && !("".equals(paymentStatus))) {
				GoodsOrderInfo goodsOrderInfo = new GoodsOrderInfo();
				goodsOrderInfo.setOrderId(info.getOrderId());
				if ("1".equals(paymentStatus)) { // 成功
					goodsOrderInfo.setOperator(info.getOperator());
					isPay = "3";
					goodsOrderInfo.setIsPay(isPay); // 退款成功

					String orderId = info.getOrderId();
					// 退款成功，通知下游用户
					DeductionRefund.noticeUserRefundMsg(orderId, deReFunInfo,
							goodsOrderDAO, downstreamUserDAO, goodsOrderLogDAO);
				} else if ("2".equals(paymentStatus)) { // 失败
					isPay = "2";
					goodsOrderInfo.setIsPay(isPay); // 退款失败
				}

				// 更新订单
				try {
					goodsOrderDAO.update(goodsOrderInfo);
				} catch (Exception e) {
					log.error(e);
					throw new ServerDisponseException(
							ExceptionCodeDes.ACCESS_DATABASE_ERROR.getCode(),
							ExceptionCodeDes.ACCESS_DATABASE_ERROR
									.getDescription());
				}

				String resultBody = isPay;
				return resultBody;
			}
		}

		return null;
	}

	/**
	 * 订单充值失败退款
	 * 
	 * @param info
	 * @return
	 */
	private boolean checkDataOfRefund(GoodsOrderInfo info) {
		boolean flag = false;
		// 下游承包商账号
		String contractId = info.getContractId();
		// 手拉手订单号
		String orderId = info.getOrderId();
		// 支付单号
		String paymentOrderNo = info.getPaymentOrderNo();
		// 退款金额
		String totalPrice = info.getTotalPrice() + "";
		// 下游用户IP
		String merchantIP = info.getMerchantIP();

		if ("".equals(contractId) || contractId == null) {
			throw new ServerDisponseException(
					ExceptionCodeDes.USER_ID_NULL.getCode(),
					ExceptionCodeDes.USER_ID_NULL.getDescription());
		} else if ("".equals(orderId) || orderId == null) {
			throw new ServerDisponseException(
					ExceptionCodeDes.SLS_ORDERNO_NULL.getCode(),
					ExceptionCodeDes.SLS_ORDERNO_NULL.getDescription());
		} else if ("".equals(paymentOrderNo) || paymentOrderNo == null) {
			throw new ServerDisponseException(
					ExceptionCodeDes.PAYMENT_NO_NULL.getCode(),
					ExceptionCodeDes.PAYMENT_NO_NULL.getDescription());
		} else if ("".equals(totalPrice) || totalPrice == null) {
			throw new ServerDisponseException(
					ExceptionCodeDes.TRADE_AMOUNT_NULL.getCode(),
					ExceptionCodeDes.TRADE_AMOUNT_NULL.getDescription());
		} else if ("".equals(merchantIP) || merchantIP == null) {
			throw new ServerDisponseException(
					ExceptionCodeDes.USER_IP_NULL.getCode(),
					ExceptionCodeDes.USER_IP_NULL.getDescription());
		} else {
			flag = true;
		}

		return flag;
	}

	/**
	 * 获取下载对账文件的url
	 * 
	 * @param body
	 * @param head
	 * @return
	 * @throws ServerDisponseException
	 */
	@Override
	public String queryReconciliationUrl(String body, Head head)
			throws ServerDisponseException {
		// TODO Auto-generated method stub
		return null;
	}

	/**
	 * 从商品信息表中，查询该商品的售价
	 * 
	 * @param goodsId
	 * @return
	 */
	private String queryGoodsSalePrice(String goodsId, Head head) {
		String salePrice = "";
		GoodsManageInfo goodsManageInfo = null;
		try {
			goodsManageInfo = goodsInfoManageDAO
					.queryGoodsInfoByGoodsId(goodsId);
		} catch (Exception e) {
			log.error("Service处理[" + head.getRequestId() + "]的请求出现异常！");
			throw new ServerDisponseException(
					ExceptionCodeDes.ACCESS_DATABASE_ERROR.getCode(),
					ExceptionCodeDes.ACCESS_DATABASE_ERROR.getDescription());
		}

		if (goodsManageInfo != null) {
			salePrice = goodsManageInfo.getCommonSalePrice() + "";
		}

		return salePrice;
	}

	/**
	 * 数据校验
	 * 
	 * @param info
	 * @param reqId
	 * @return
	 * @throws ServerDisponseException
	 */
	private boolean checkDataOfPickingUpCard(SLSHttpInterfaceInfo info,
			String reqId) throws ServerDisponseException {
		boolean flag = false;
		String userNo = info.getUserNo();
		String goodsId = info.getGoodsId();
		String buyNum = info.getBuyNum();
		String unitPrice = info.getUnitPrice();
		String totalPrice = info.getTotalPrice();
		String ptOrderNo = info.getPtOrderNo();
		String ptOrderTime = info.getPtOrderTime();

		if ("".equals(userNo) || userNo == null) {
			throw new ServerDisponseException(
					ExceptionCodeDes.USER_ID_NULL.getCode(),
					ExceptionCodeDes.USER_ID_NULL.getDescription());
		} else if ("".equals(goodsId) || goodsId == null) {
			throw new ServerDisponseException(
					ExceptionCodeDes.GOODS_ID_EMPTY.getCode(),
					ExceptionCodeDes.GOODS_ID_EMPTY.getDescription());
		} else if ("".equals(unitPrice) || unitPrice == null) {
			throw new ServerDisponseException(
					ExceptionCodeDes.GOODS_SUPPLY_PRICE_NULL.getCode(),
					ExceptionCodeDes.GOODS_SUPPLY_PRICE_NULL.getDescription());
		} else if ("".equals(totalPrice) || totalPrice == null) {
			throw new ServerDisponseException(
					ExceptionCodeDes.TRADE_AMOUNT_NULL.getCode(),
					ExceptionCodeDes.TRADE_AMOUNT_NULL.getDescription());
		} else if ("".equals(ptOrderNo) || ptOrderNo == null) {
			throw new ServerDisponseException(
					ExceptionCodeDes.COOPERATION_PLATFORM_ORDERNO_NULL
							.getCode(),
					ExceptionCodeDes.COOPERATION_PLATFORM_ORDERNO_NULL
							.getDescription());
		} else if ("".equals(ptOrderTime) || ptOrderTime == null) {
			throw new ServerDisponseException(
					ExceptionCodeDes.PTORDER_TIME_NULL.getCode(),
					ExceptionCodeDes.PTORDER_TIME_NULL.getDescription());
		} else if ("".equals(buyNum) || buyNum == null) {
			throw new ServerDisponseException(
					ExceptionCodeDes.CARD_NUM_EMPTY.getCode(),
					ExceptionCodeDes.CARD_NUM_EMPTY.getDescription());
		} else {
			flag = true;
		}

		return flag;
	}

	/**
	 * 数据校验
	 * 
	 * @param info
	 * @param reqId
	 * @return
	 * @throws ServerDisponseException
	 */
	protected boolean checkDataOfInsertOfTrading(SLSHttpInterfaceInfo info,
			String reqId) throws ServerDisponseException {
		boolean flag = false;
		String userId = info.getUserNo();
		String goodsId = info.getGoodsId();
		String ptOrderNo = info.getPtOrderNo();
		String ptPayTime = info.getPtPayTime();
		String buyNum = info.getBuyNum();
		String unitPrice = info.getUnitPrice();
		String totalPrice = info.getTotalPrice();
		String gameAccount = info.getGameAccount();

		if ("".equals(userId) || userId == null) {
			throw new ServerDisponseException(
					ExceptionCodeDes.COOPERATION_USERNO_NULL.getCode(),
					ExceptionCodeDes.COOPERATION_USERNO_NULL.getDescription());
		} else if ("".equals(goodsId) || goodsId == null) {
			throw new ServerDisponseException(
					ExceptionCodeDes.GOODS_ID_EMPTY.getCode(),
					ExceptionCodeDes.GOODS_ID_EMPTY.getDescription());
		} else if ("".equals(ptOrderNo) || ptOrderNo == null) {
			throw new ServerDisponseException(
					ExceptionCodeDes.COOPERATION_PLATFORM_ORDERNO_NULL
							.getCode(),
					ExceptionCodeDes.COOPERATION_PLATFORM_ORDERNO_NULL
							.getDescription());
		} else if ("".equals(ptPayTime) || ptPayTime == null) {
			throw new ServerDisponseException(
					ExceptionCodeDes.BUYERS_PAYMENT_TIME_NULL.getCode(),
					ExceptionCodeDes.BUYERS_PAYMENT_TIME_NULL.getDescription());
		} else if ("".equals(buyNum) || buyNum == null) {
			throw new ServerDisponseException(
					ExceptionCodeDes.BUYE_GOODS_NUM_NULL.getCode(),
					ExceptionCodeDes.BUYE_GOODS_NUM_NULL.getDescription());
		} else if ("".equals(unitPrice) || unitPrice == null) {
			throw new ServerDisponseException(
					ExceptionCodeDes.GOODS_SUPPLY_PRICE_NULL.getCode(),
					ExceptionCodeDes.GOODS_SUPPLY_PRICE_NULL.getDescription());
		} else if ("".equals(totalPrice) || totalPrice == null) {
			throw new ServerDisponseException(
					ExceptionCodeDes.TRADE_AMOUNT_NULL.getCode(),
					ExceptionCodeDes.TRADE_AMOUNT_NULL.getDescription());
		} else if ("".equals(gameAccount) || gameAccount == null) {
			throw new ServerDisponseException(
					ExceptionCodeDes.GAME_PLAYER_ACCOUNT_NULL.getCode(),
					ExceptionCodeDes.GAME_PLAYER_ACCOUNT_NULL.getDescription());
		} else {
			flag = true;
		}

		return flag;
	}

	/**
	 * 数据校验
	 * 
	 * @param info
	 * @param reqId
	 * @return
	 * @throws ServerDisponseException
	 */
	private boolean checkDataOfQueryGoodsOfByBrandId(GoodsManageInfo goodsInfo,
			String reqId) throws ServerDisponseException {
		boolean flag = false;
		// 品牌Id
		String brandId = goodsInfo.getGoodsCategoryId();
		if ("".equals(brandId) || brandId == null) {
			throw new ServerDisponseException(
					ExceptionCodeDes.BRAND_ID_NULL.getCode(),
					ExceptionCodeDes.BRAND_ID_NULL.getDescription());
		} else {
			flag = true;
		}

		return flag;
	}

	/**
	 * 数据校验
	 * 
	 * @param info
	 * @param reqId
	 * @return
	 * @throws ServerDisponseException
	 */
	private boolean checkDataOfQueryOneGoodsOfDetail(SLSHttpInterfaceInfo info,
			String reqId) throws ServerDisponseException {
		boolean flag = false;
		// 商品Id
		String goodsId = info.getGoodsId();
		if ("".equals(goodsId) || goodsId == null) {
			throw new ServerDisponseException(
					ExceptionCodeDes.GOODS_ID_EMPTY.getCode(),
					ExceptionCodeDes.GOODS_ID_EMPTY.getDescription());
		} else {
			flag = true;
		}

		return flag;
	}

	/**
	 * 发送http请求，并对返回的xml格式的结果进行解析
	 * 
	 * @param url
	 * @return
	 */
	private Map<String, Object> sendHttpRequestOfGoodsDetail(String url,
			String originalGoodsId) {
		Map<String, Object> map = null;
		HttpClient httpClient = new HttpClient();
		try {
			String supplyEncode = "GBK";
			String xmlStr = httpClient.doGet(url, supplyEncode);
			map = NutsNetResponseDomParseXml.parseXmlOfGoodsDetailForTrade(
					xmlStr, originalGoodsId);
		} catch (Exception e) {
			log.error(e);
			throw new ServerDisponseException(
					ExceptionCodeDes.HTTP_URL_FAILED.getCode(),
					ExceptionCodeDes.HTTP_URL_FAILED.getDescription());
		}

		return map;
	}

	/**
	 * 坚果网络商品详细访问Url
	 * 
	 * @param originalGoodsId
	 * @return
	 */
	private String assembleNutsNetUrl(String originalGoodsId) {
		NutsNetServerInfo nutsNetServerInfo = null;
		String serverIp = "";
		String serverPort = "";
		String filePath = "conf" + File.separator + "nutsNetServer.xml";
		List<NutsNetServerInfo> list = NutsNetServerSaxParseXml
				.parseXmlString(filePath);
		nutsNetServerInfo = list.get(0);
		if (nutsNetServerInfo != null) {
			serverIp = nutsNetServerInfo.getIp().trim();
			serverPort = nutsNetServerInfo.getPort().trim();
		}

		StringBuffer strBuf = new StringBuffer();
		strBuf.append("http://");
		strBuf.append(serverIp);
		strBuf.append(":");
		strBuf.append(serverPort);
		strBuf.append("/");
		strBuf.append("xml");
		strBuf.append("/");
		strBuf.append(originalGoodsId);
		strBuf.append(".xml");

		String url = strBuf.toString().trim();
		return url;
	}

	/**
	 * http请求url所传参数字符串拼接<br>
	 * 殴飞直充接口
	 * 
	 * @param info
	 * 
	 * @param originalGoodsId
	 * 
	 * @param orderId
	 * 
	 * @return
	 * @throws UnsupportedEncodingException
	 */
	private String assembleParaOfOhFeiPickingUpCard(SLSHttpInterfaceInfo info,
			String originalGoodsId, String orderId) {
		// SP编码如（A00001）在登陆系统时得到以A开头的编号
		String userid = "";
		// 登陆密码
		String pwd = "";
		//
		String version = "";
		// 从xml配置文件中读取访问地址
		List<OhFeiServerInfo> serverList = OhFeiServerSaxParseXml
				.parseXmlString("conf" + File.separator + "ohFeiServer.xml");
		if (serverList.size() > 0) {
			for (OhFeiServerInfo ohFeiServerInfo : serverList) {
				userid = ohFeiServerInfo.getUserid().trim();
				pwd = ohFeiServerInfo.getUserpws().trim();
				version = ohFeiServerInfo.getVersion().trim();
			}
		}

		// SP接入密码(为账户密码的MD5值，如登陆密码为111111,此时这个值为md5(“111111”) (32位小写)
		String userpws = UtilMD5Encryption.createMD5Encryption(pwd);
		// 所需提货商品的编码(需和CP商品编码一一对应,需22开头的编码)
		String cardid = originalGoodsId;
		// 购买数量
		String cardnum = info.getBuyNum();
		// Sp商家的订单号
		String sporder_id = orderId;
		// 手拉手订单生成时间
		String sporder_time = ServerDateAndTime.getNowDateTime();
		String data1 = userid + userpws + cardid + cardnum + sporder_id
				+ sporder_time;
		String keyStr = "OFCARD";
		String data = data1 + keyStr;

		// MD5后字符串
		String md5_str1 = UtilMD5Encryption.createMD5Encryption(data);
		String md5_str = md5_str1.toUpperCase();

		StringBuffer strBuf = new StringBuffer();
		strBuf.append("userid=");
		strBuf.append(userid);
		strBuf.append("&");
		strBuf.append("userpws=");
		strBuf.append(userpws);
		strBuf.append("&");
		strBuf.append("cardid=");
		strBuf.append(cardid);
		strBuf.append("&");
		strBuf.append("cardnum=");
		strBuf.append(cardnum);
		strBuf.append("&");
		strBuf.append("sporder_id=");
		strBuf.append(sporder_id);
		strBuf.append("&");
		strBuf.append("sporder_time=");
		strBuf.append(sporder_time);
		strBuf.append("&");
		strBuf.append("md5_str=");
		strBuf.append(md5_str);
		strBuf.append("&");
		strBuf.append("version=");
		strBuf.append(version);

		String result = strBuf.toString().trim();

		return result;
	}

	/**
	 * http请求url所传参数字符串拼接<br>
	 * 殴飞直充接口
	 * 
	 * @param info
	 * 
	 * @param originalGoodsId
	 * 
	 * @param orderId
	 * 
	 * @param orderTime
	 * 
	 * @return
	 * @throws UnsupportedEncodingException
	 */
	private String assembleParameterOfOhFeiTrade(SLSHttpInterfaceInfo info,
			String originalGoodsId, String orderId, String orderTime) {

		// SP编码如（A00001）在登陆系统时得到以A开头的编号
		String userid = "";
		// 登陆密码
		String pwd = "";
		//
		String version = "";
		String key = "";
		String notifyUrl = "";
		// 从xml配置文件中读取访问地址
		List<OhFeiServerInfo> serverList = OhFeiServerSaxParseXml
				.parseXmlString("conf" + File.separator + "ohFeiServer.xml");
		if (serverList != null && serverList.size() > 0) {
			for (OhFeiServerInfo ohFeiServerInfo : serverList) {
				key = ohFeiServerInfo.getKey();
				if (StringUtils.isNotEmpty(key)) {
					key = key.trim();
				}
				userid = ohFeiServerInfo.getUserid();
				if (StringUtils.isNotEmpty(userid)) {
					userid = userid.trim();
				}
				pwd = ohFeiServerInfo.getUserpws();
				if (StringUtils.isNotEmpty(pwd)) {
					pwd = pwd.trim();
				}
				version = ohFeiServerInfo.getVersion();
				if (StringUtils.isNotEmpty(version)) {
					version = version.trim();
				}
				notifyUrl = ohFeiServerInfo.getNotifyUrl();
				if (StringUtils.isNotEmpty(notifyUrl)) {
					notifyUrl = notifyUrl.trim();
				}
			}
		}

		// SP接入密码(为账户密码的MD5值，如登陆密码为111111,此时这个值为md5(“111111”) (32位小写)
		String userpws = UtilMD5Encryption.createMD5EncryptionOfGBK(pwd);
		// 所需提货商品的编码(需和CP商品编码一一对应,需22开头的编码)
		String cardid = originalGoodsId;
		// 购买数量
		String cardnum = info.getBuyNum();
		// Sp商家的订单号
		String sporder_id = orderId;
		// 手拉手订单生成时间
		String sporder_time = orderTime;
		// 游戏玩家账号
		String game_userid = info.getGameAccount();
		// 游戏所在区域
		String game_area = info.getGameArea();
		// 游戏所在服务器组
		String game_srv = info.getGameServer();

		String data = userid + userpws + cardid + cardnum + sporder_id
				+ sporder_time + game_userid;
		if (StringUtils.isNotEmpty(game_area)) {
			data += game_area;
		}
		if (StringUtils.isNotEmpty(game_srv)) {
			data += game_srv;
		}
		// MD5后字符串
		String md5_str = UtilMD5Encryption.createMD5EncryptionOfGBK(data + key);
		md5_str = md5_str.toUpperCase();

		StringBuffer strBuf = new StringBuffer();
		strBuf.append("userid=");
		strBuf.append(userid);
		strBuf.append("&");
		strBuf.append("userpws=");
		strBuf.append(userpws);
		strBuf.append("&");
		strBuf.append("cardid=");
		strBuf.append(cardid);
		strBuf.append("&");
		strBuf.append("cardnum=");
		strBuf.append(cardnum);
		strBuf.append("&");
		strBuf.append("sporder_id=");
		strBuf.append(sporder_id);
		strBuf.append("&");
		strBuf.append("sporder_time=");
		strBuf.append(sporder_time);
		strBuf.append("&");
		strBuf.append("game_userid=");
		strBuf.append(game_userid);
		if (StringUtils.isNotEmpty(game_area)) {
			strBuf.append("&");
			strBuf.append("game_area=");
			strBuf.append(game_area);
		}
		if (StringUtils.isNotEmpty(game_srv)) {
			strBuf.append("&");
			strBuf.append("game_srv=");
			strBuf.append(game_srv);
		}
		strBuf.append("&");
		strBuf.append("md5_str=");
		strBuf.append(md5_str);
		strBuf.append("&");
		if (notifyUrl != null && !("".equals(notifyUrl))) {
			strBuf.append("ret_url=");
			strBuf.append(notifyUrl);
			strBuf.append("&");
		}
		strBuf.append("version=");
		strBuf.append(version);

		String result = strBuf.toString().trim();

		log.info("殴飞交易请求消息内容      \n用户编号：" + userid + "\n用户密码：" + userpws
				+ "\n商品编号：" + cardid + "\n商品数量：" + cardnum + "\n手拉手订单号："
				+ sporder_id + "\n手拉手订单时间：" + sporder_time + "\n游戏玩家账号："
				+ game_userid + "\n游戏所在区域：" + game_area + "\n游戏所在服务器组："
				+ game_srv + "\n版本号：" + version);
		return result;
	}

	/**
	 * 发送http请求，并对返回的xml格式的结果进行解析
	 * 
	 * @param url
	 * @return
	 */
	private OhFeiTradeInfo sendHttpRequestOfOhFeiDirectTrade(String url,
			Head head) {
		OhFeiTradeInfo resInfo = null;
		HttpClient httpClient = new HttpClient();
		try {
			// 供应商返回消息编码方式
			String supplyEncode = "GB2312";
			log.info("请求ID：" + head.getRequestId() + "，发送到殴飞的直充请求url参数为：" + url);
			String xmlStr = httpClient.doGet(url, supplyEncode);
			log.info("请求ID：" + head.getRequestId() + "，殴飞直充返回的结果参数为：" + xmlStr);
			// 对返回的xml格式字符串数据进行解析
			resInfo = OhFeiResOfDomParseXml
					.parseXmlOfDirectRechargeString(xmlStr);
		} catch (Exception e) {
			log.error("殴飞直充交易请求异常！", e);
			throw new ServerDisponseException(
					ExceptionCodeDes.ACCESS_DATABASE_ERROR.getCode(),
					ExceptionCodeDes.ACCESS_DATABASE_ERROR.getDescription());
		}
		String orderId = null;
		String cardId = null;
		String cardNum = null;
		String orderCash = null;
		String cardName = null;
		String sporder_id = null;
		String game_userid = null;
		String game_area = null;
		String game_srv = null;
		String game_state = null;

		if (resInfo != null) {
			orderId = resInfo.getOrderid();
			cardId = resInfo.getCardid();
			cardNum = resInfo.getCardnum();
			orderCash = resInfo.getOrdercash();
			cardName = resInfo.getCardname();
			sporder_id = resInfo.getSporder_id();
			game_userid = resInfo.getGame_userid();
			game_area = resInfo.getGame_area();
			game_srv = resInfo.getGame_srv();
			game_state = resInfo.getGame_state();
		}
		log.info("殴飞交易请求返回消息内容     \n殴飞订单号：" + orderId + "\n商品编号：" + cardId
				+ "\n购买数量：" + cardNum + "\n订单金额(元)：" + orderCash + "\n商品名称："
				+ cardName + "\n手拉手订单编号：" + sporder_id + "\n游戏用户账号："
				+ game_userid + "\n游戏大区：" + game_area + "\n游戏服务器：" + game_srv
				+ "\n游戏充值结果：" + game_state);

		return resInfo;
	}

	/**
	 * 发送http请求，并对返回的xml格式的结果进行解析
	 * 
	 * @param url
	 * @return
	 */
	private List<OhFeiTradeInfo> sendHttpRequestOfOhFeiPickingUpCard(
			String url, Head head) {
		List<OhFeiTradeInfo> resInfoList = null;
		HttpClient httpClient = new HttpClient();
		try {
			// 供应商返回消息编码方式
			String supplyEncode = "GB2312";
			log.info("请求ID：" + head.getRequestId() + "，发送到殴飞提卡接口的请求参数：" + url);
			String xmlStr = httpClient.doGet(url, supplyEncode);
			log.info("请求ID：" + head.getRequestId() + "，殴飞提卡接口返回的结果：" + xmlStr);
			// 对返回的xml格式字符串数据进行解析
			resInfoList = OhFeiResOfDomParseXml
					.parseXmlOfCardTradeString(xmlStr);
		} catch (Exception e) {
			log.error("请求ID：" + head.getRequestId() + "，殴飞提卡请求出现异常！", e);
			throw new ServerDisponseException(
					ExceptionCodeDes.HTTP_URL_FAILED.getCode(),
					ExceptionCodeDes.HTTP_URL_FAILED.getDescription());
		}

		return resInfoList;
	}

	/**
	 * 下游用户身份校验
	 * 
	 * @param userNo
	 * @return
	 */
	protected String checkIdentity(String userNo, String userIP,
			boolean isCheckIP) {
		String result = "";
		DownstreamUserInfo downstreamUserInfo = null;
		// 根据用户账号 查询记录
		downstreamUserInfo = downstreamUserDAO.queryUserByUserNO(userNo);

		if (downstreamUserInfo == null) {
			result = "104"; // 合作方用户不存在
		} else {
			if (isCheckIP) {
				String bindIPList = downstreamUserInfo.getBindIPList();
				boolean flag = true;
				flag = SlsDataCheck.checkBindIP(userIP, bindIPList);
				if (!flag) {
					result = "105"; // 绑定的Ip地址不匹配
				}
			}
		}

		return result;
	}

	/**
	 * 按元充值时，(上游)交易总费用的计算
	 * 
	 * @param info
	 * @param chargeTypeName
	 * @param originalGoodsId
	 * @return
	 */
	private String calculateTotalPriceOfSupply(SLSHttpInterfaceInfo info,
			String chargeTypeName, String originalGoodsId, String unitPrice,
			String sum) {

		String totalPrice = sum;
		// 判断该字符串中是否含有"元"
		boolean flag1 = ProcessString.isContainYuan(chargeTypeName);
		if (flag1) {
			boolean flag2 = ProcessString.isHasDigital(chargeTypeName);
			if (flag2) {
				// 充值方式或计费类型Id
				String hidChargeType = "";
				ChargeTypeInfo chargeTypeInfo = new ChargeTypeInfo();
				chargeTypeInfo.setGoodsId(originalGoodsId);
				chargeTypeInfo.setChargetypeName(chargeTypeName);
				hidChargeType = chargeTypeInfoDAO
						.queryChargeType(chargeTypeInfo);
				int hidChargeTypeVal = Integer.parseInt(hidChargeType);

				String buyNum = info.getBuyNum();
				int buyNumVal = Integer.parseInt(buyNum);
				int unitPriceVal = DataConversion
						.converStringToInteger(unitPrice);
				int moneyVal = buyNumVal * unitPriceVal * hidChargeTypeVal;
				String moneyStr = moneyVal + "";
				String money = DataConversion.converIntegerToString(moneyStr);
				totalPrice = money;
			}
		}

		return totalPrice;
	}

}
